Pregunta

I have a Gradle build script containing the following dependencies (and not much else):

dependencies {
    testCompile "com.foo:lib-foo:2.0.0-SNAPSHOT"
    testCompile "com.foo:lib-bar:2.0.2-SNAPSHOT"
}

The dependencies are resolved from a Maven repository (Sonatyp Nexus OSS). lib-bar has a dependency on lib-foo declared in its pom.xml:

<dependency>
    <groupId>com.foo</groupId>
    <artifactId>lib-foo</artifactId>
    <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>

When I remove the dependency on lib-bar from my build script (and all code that uses it), everything compiles fine. When the I declare dependency, Gradle complains:

Could not resolve all dependencies for configuration ':testCompile'.
> Could not find any version that matches com.foo:lib-foo:[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT).
  Required by:
      :my-project:unspecified > com.foo:lib-bar:2.0.2-SNAPSHOT

The same scenario works fine with Maven.

The tutorial does not mention any limitations on Gradles ability to handle transitive dependencies or version ranges that would explain this, so I assumed this would work. Am I using it wrong? How can I make Gradle resolve that dependency?

P.S.:

When I run gradle test --info I get this:

Resource missing. [HTTP HEAD: https://nexus.foo.com/nexus/content/groups/public/com/foo/lib-foo/2.0.0-SNAPSHOT/lib-foo-2.0.0-SNAPSHOT.pom]
Resource missing. [HTTP HEAD: https://nexus.foo.com/nexus/content/groups/public/com/foo/lib-foo/2.0.0-SNAPSHOT/lib-foo-2.0.0-SNAPSHOT.jar]

These resources do indeed not exists, because the snapshots have file names with timestamps. But shouldn't Gradle use maven-metadata.xml to resolve that? And why does it work when I declare the dependency directly?

¿Fue útil?

Solución 2

While Peter provided useful insight and the final hint (RTFM), he did not post the solution, so here it comes:

dependencies {
    testCompile "com.foo:lib-foo:2.0.0-SNAPSHOT"
    testCompile("com.foo:lib-bar:2.0.2-SNAPSHOT") {
        transitive = false
    }
}

This tells Gradle to not resolve transitive dependencies for lib-bar. This works without modifications in this case because the only transitive dependency of lib-bar is already included.

Otros consejos

Gradle's support for version ranges is derived from Ivy's. I think what happens is that snapshots as bounds of version ranges aren't supported, and hence not recognized as such. As a consequence, Gradle tries to resolve 2.0.0-SNAPSHOT and 3.0.0-SNAPSHOT as static versions.

What's the meaning of version ranges with snapshot bounds? Will they match non-snapshot versions (e.g. 2.5)? And what's the meaning of [2.0.0, 3.0.0-SNAPSHOT) then? I haven't seen this kind of version range defined or mentioned in any Maven documentation. If this does work consistently in recent Maven versions, you may want to file an improvement request over at http://forums.gradle.org.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top