Gradle 由于 Nexus 返回 400 错误请求,构建失败

Gradle build fails because of Nexus returning 400 Bad Request

我们有一个全公司范围的 Nexus 3 服务器

开发人员使用两个存储库:

两个存储库都用于 Gradle 构建:

repositories {
    maven {
        name "snapshots"
        url "http://nexus3.server:8081/repository/maven-snapshots"
    }

    maven {
        name "releases"
        url "http://nexus3.server:8081/repository/maven-releases"
    }
}

现在,当 Gradle 尝试解决快照依赖时,它会询问发布存储库,Nexus 会回答

Error 400 Bad Request
Repository version policy: RELEASE does not allow version: 1.0-SNAPSHOT

并且构建失败

> Could not resolve group.id:artifact-id:1.0-SNAPSHOT.
 Required by:
     :my-project:unspecified
  > Could not resolve group.id:artifact-id:1.0-SNAPSHOT.
     > Could not get resource 'http://nexus3.server:8081/repository/maven-releases/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-SNAPSHOT.pom'.
        > Could not GET 'http://nexus3.server:8081/repository/maven-releases/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-SNAPSHOT.pom'. Received status code 400 from server: Bad Request

我需要如何配置 Gradle 以便忽略此错误并尝试下一个存储库 ("snapshots")?或者是否可以将 Nexus 配置为 return 404 Not Found 而不是 400 Bad Request?

版本:Gradle2.9

查看 gradle usage as well as the example projects 的 Nexus Repository Manager 3 文档。那应该向您展示如何使用 init.gradle 从存储库组下载。

RaGe 的评论是一个很好的提示:依赖项既不在 snapshots 中也不在 releases 中,而是在我不知道的第三个存储库中。将第三个存储库添加到 Gradle 后,依赖关系得到解决。