y986482151 2024-03-22 11:31 采纳率: 0%
浏览 138

[已解决]gradle配置私有http协议的maven仓库地址报错

在使用gradle构建项目时,用的私有Maven仓库地址是http协议的,会报这个错误


A problem occurred configuring root project 'erms'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://11.71.3.109:30000/repository/maven-public)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.6.4/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 

在网上找了半天教程后说添加一个allowInsecureProtocol = true配置就可以,结果还是不行,会报allowInsecureProtocol 未知属性


Build file 'D:\Code\erms-master\build.gradle' line: 11

A problem occurred evaluating root project 'erms'.
> Could not find method allowInsecureProtocol() for arguments [true] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

我的build.gradle文件是这样写的

buildscript {

    repositories {

//        mavenLocal()
        maven { url 'http://ip::port/repository/maven-public'}
//        allowInsecureProtocol  true
        gradlePluginPortal()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:1.1.0"
    }
}

【解决方案】在上述配置依然报错后,可以将 allowInsecureProtocol true写在 url之后可以解决报错。。

    repositories {

//        mavenLocal()
        maven { url 'http://ip::port/repository/maven-public'
                       allowInsecureProtocol  true
        }
//       
        gradlePluginPortal()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:1.1.0"
    }
}

  • 写回答

3条回答 默认 最新

  • 码农阿豪@新空间代码工作室 Java领域优质创作者 2024-03-22 11:31
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    问题描述: 在使用 Gradle 构建项目时,使用的私有 Maven 仓库地址是 http 协议的,在配置 classpath 时会报错 : A problem occurred configuring root project 'erms'. Could not resolve all dependencies for configuration ':classpath'. Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://11.71.3.109:30000/repository/maven-public)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.6.4/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 解决方案: 根据报错信息,是由于http协议是不安全的,需要改为https或允许使用不安全的协议。可以在build.gradle文件中添加配置项: maven {
       url "http://11.71.3.109:30000/repository/maven-public"
       allowInsecureProtocol = true
    

    } 示例代码: buildscript { repositories { maven { url "http://11.71.3.109:30000/repository/maven-public" allowInsecureProtocol = true } } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' } } 注:此处示例为 Android 项目的 build.gradle 文件。

    评论

报告相同问题?

问题事件

  • 修改了问题 3月23日
  • 修改了问题 3月22日
  • 创建了问题 3月22日

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?