Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build fails because of Nexus returning 400 Bad Request

Tags:

gradle

nexus

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

like image 904
Roland Weisleder Avatar asked Nov 02 '16 15:11

Roland Weisleder


2 Answers

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.

like image 86
Manfred Moser Avatar answered Oct 24 '22 09:10

Manfred Moser


RaGe's comment was a good hint: The dependency was neither in snapshots nor in releases but in a third repository which I was not aware of. After adding the third repository to Gradle the dependency was resolved.

like image 40
Roland Weisleder Avatar answered Oct 24 '22 11:10

Roland Weisleder