简体   繁体   中英

Gradle won't resolve dependency (Maven will)

My project has dependencies configured through gradle. I would like to add the following dependency:

compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', version: '2.3.1'

Which can be found in the following repository (which I have added to my build.gradle):

maven {
    url "http://maven.restlet.org"
}

However when I do that I get the following error:

Could not find org.restlet.jse:org.restlet.lib.swagger-models:1.5.0-SNAPSHOT.
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/maven-metadata.xml
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/org.restlet.lib.swagger-models-1.5.0-null-null.pom
http://maven.restlet.org/org/restlet/jse/org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/org.restlet.lib.swagger-models-1.5.0-null-null.jar
Required by: org.restlet.jse:org.restlet.ext.apispark:2.3.1

I can see that the jar is in fact in the repository however Gradle is not looking for it in the right location for reasons unknown to me. Why is it not using the version in the filename but rather 1.5.0-null-null.

I have made a made a Maven project with the same dependency defined in the pom.xml which works.

Link to working pom.xml that has same dependency

How can this issue be resolved? I'm at this point also interesting in more manual solutions :) Thank you.

Diagnosis

It seems to be related to snapshot " uniqueness ". For information on Maven repositories, snapshots artifacts can be deployed " unique " or " non-unique ".

  • Unique snapshots: Each time you deploy a snapshot, it is tagged with a timestamp and a buildNumber , these timestamp and buildNumber are written in the maven-metadata.xml file and they are appended to its name that ends up like: artifactName-version-timestamp-buildNumber.jar .
  • Non-unique snapshots: Each time you deploy a snapshot it overwrites the previous version, his name ends up like: artifactName-version.jar .

It is recommended to use unique snapshot as one can refer precisely to one version of the artifact if needed.

The problem is that " http://maven.restlet.org " seems to use non-unique snapshots and sadly, gradle seems to have problems to deal with non-unique snapshots: https://issues.gradle.org/browse/GRADLE-3164 .

If you look at http://maven.restlet.com/org/restlet/jse/org.restlet.lib.org.restlet.lib.swagger-models/1.5.0-SNAPSHOT/maven-metadata.xml you can clearly see null in timestamp and buildNumber tags:

<metadata>
  [...]
  <versioning>
    <snapshot>
      <timestamp>null</timestamp>
      <buildNumber>null</buildNumber>
    </snapshot>
    <lastUpdated>null</lastUpdated>
  </versioning>
</metadata>

I think that's where the " null-null " comes from.

Solution 1 - flatDir

To deal with it you can manually download the artifact, put it in a directory, for example "lib" and create a flatDir repository:

repositories {
    [...]
    flatDir {
        dirs 'lib'
    }
    [...]
}

It's not an ideal solution, but it works.

Solution 2 - jcenter repository

Suggested by Opal

Add the jcenter repository that contains your missing dependency and that Gradle handles well.

Since Gradle 1.7 you can simply define it with:

repositories {
    [...]
    jcenter()
    [...]
}

It seems that you need other repositories to download all the dependencies. Probably maven handle this transparently. The following script downloads all dependencies successfully when cp task is run:

apply plugin: 'java'

configurations {
   lol
}

repositories {
   jcenter()
   mavenCentral()
   maven {
      url "http://maven.restlet.org"
   }
   maven {
      url "https://repository.mulesoft.org/nexus/content/repositories/public/"
   }
}

dependencies {
   lol group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', version: '2.3.1'
}

task cp(type: Copy) {
   from configurations.lol
   into 'deps'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM