首页 > 解决方案 > Gradle 允许不安全的存储库镜像

问题描述

我正在开始一个新项目。我不需要任何本地依赖项。但是在我们的组织中,我们使用在 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 中配置不安全的连接以使其满意,例如

    repositories {
        maven {
            url "http://nexus-local.org.com/nexus/content/groups/public"
            allowInsecureProtocol = true
        }
    }
    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.

我究竟做错了什么?

标签: gradlebuild.gradlegradle-kotlin-dsl

解决方案


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

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

希望这有效。


推荐阅读