Gradle build fails because of Nexus returning 400 Bad Request

gradlenexus

We have a company-wide Nexus 3 server which

  • hosts our own artifacts and
  • is used as proxy to Maven Central and other repos.

The developers use two repositories:

  • maven-releases for all released/stable artifacts with the version policy "Release" and
  • maven-snapshots for all snapshots artifacts with the version policy "Snapshot".

Both repositories are used in a Gradle build:

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

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

Now when Gradle tries to resolve a snapshot-dependency it asks the releases-repository, Nexus answers with

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

and the build fails with

> 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

How do I need to configure Gradle so that this error is ignored and the next repository ("snapshots") is tried? Or is it possible to configure Nexus to return 404 Not Found instead of 400 Bad Request?

Version: Gradle 2.9

Best Answer

Check out the Nexus Repository Manager 3 documentation for gradle usage as well as the example projects. That should show you how to use a init.gradle for downloading from the repository group.

Related Topic