Gradle 允许不安全的存储库镜像

标签 gradle build.gradle gradle-kotlin-dsl

我正在开始一个新项目。为此我不需要任何本地依赖项。但在我们的组织中,我们使用在 http 上运行的本地 Maven 镜像。使用maven settings.xml

<mirrors>
    <mirror>
        <id>nexus-local</id>
        <mirrorOf>external:*</mirrorOf>
        <url>http://nexus-local.org.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>

我尝试在 gradle 中配置不安全连接以使其满意,例如

  • 构建.gradle
    repositories {
        maven {
            url "http://nexus-local.org.com/nexus/content/groups/public"
            allowInsecureProtocol = true
        }
    }
  • build.gradle.kts
    repositories {
        maven {
            url = uri("http://nexus-local.org.com/nexus/content/groups/public")
            isAllowInsecureProtocol = true
        }
    }

但是在这两种情况下,当我运行 gradle 时,它​​都会因错误而崩溃(因此结果与没有此配置时的结果相同):

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

我做错了什么?

最佳答案

刚刚在我的组织中遇到了这个问题。通过在 ~/.gradle/init.gradle 中添加以下内容解决了这个问题

allprojects {
    repositories {
        maven {
          url "http://artifactory.myorg.org/repo/"
          allowInsecureProtocol true
        }
        mavenLocal()
    }
}

希望这能起作用。

关于Gradle 允许不安全的存储库镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69135147/

相关文章:

android - 多次定义BuildConfig,Gradle Test Build报错

java - 如果sonarqube中的主要问题数量大于50,要使我们的本地构建失败

kotlin - 如何使用 Kotlin DSL 替换资源文件中的 token

gradle-kotlin-dsl - 如何在 Kotlin Buildscript 中应用 Google 服务插件

android - 使用Flutter执行任务 ':app:processReleaseResources' image_picker失败

gradle - 对多模块构建中的所有子项目应用 withJavadocJar() 和 withSourcesJar()

java - 将 firebase 添加到使用 gradle 构建的 libgdx 项目

gradle - 未解析的引用 : sourceSets for Gradle Kotlin DSL

java - 如果 Gradle 中的字母全部大写,无法创建工作 jar 文件?

Gradle 任务删除目录中的内容但排除 jar 文件