Transitive Dependencies: Connecting Two Projects

GradleCrew,

  1. I have two projects: A and B.

  2. Project A depends on ZeroMQ jar ( and many other jars, but let’s take one as an example )

  3. Project A is built, uploadArchives to nexus repo as a snapshot ( projectA-0.0.1.BUILD-SNAPSHOT )

  4. Project B depends on project A as a JAR => “projectA-0.0.1.BUILD-SNAPSHOT.jar”

  5. Project B is runnable, hence it’d need all the A’s dependencies to run succesfully

How do I make Project B pull all the A’s dependencies?

Things I tried in Project B:

allprojects {
   configurations.all {
 transitive = true
   }
}
runtime( 'org.xyz:projectA:0.0.1.BUILD-SNAPSHOT' ) { transitive = true }

and many other things.

Thank you!

In general ( as a side feedback ): it would be a lot easier to have a short and concise summary of all the “most/frequently used” options / Gradle variables, as oppose to have it spread out over the long guide. But that is besides the point.

How do I make Project B pull all the A’s dependencies?

What exactly do you mean by that? If you declare a dependency on A, you will automatically get A’s dependencies as well. Try:

dependencies {
  compile 'org.xyz:projectA:0.0.1.BUILD-SNAPSHOT'
}
  task printDeps << {
  configurations.compile.each { println it }
}

@Peter,

That was my understanding too. But all I get is:

$ gradle printDeps
:printDeps
/Users/user/.gradle/cache/org.xyz/projectA/jars/projectA-0.0.1.BUILD-SNAPSHOT.jar
  BUILD SUCCESSFUL
  Total time: 8.252 secs

While in nexus repo, where project B is pulling project A from, I can look at project’s A POM and see many dependencies.

What is interesting, once the project A gets pulled into Gradle cache, I can’t see any of its dependencies in ivy.xml:

$ cat ~/.gradle/cache/org.xyz/projectA/ivy-0.0.1.BUILD-SNAPSHOT.xml
 <?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
 <info organisation="org.xyz"
  module="projectA"
  revision="0.0.1.BUILD-SNAPSHOT"
  status="release"
  publication="20111101200417"
  default="true"
 />
 <configurations>
  <conf name="default" visibility="public"/>
 </configurations>
 <publications>
  <artifact name="projectA" type="jar" ext="jar" conf="default"/>
 </publications>
</ivy-module>

My guess is that for some reason, project A’s pom.xml isn’t found and a default ivy.xml created. What does your ‘repositories’ section look like?

for project B? Here it is:

repositories {
      mavenCentral()
    mavenRepo urls: ["http://repository.jboss.org/nexus/content/groups/public/",
                       "http://host/nexus/content/groups/public/",
                     "http://host/nexus/content/repositories/snapshots/",
                       "http://scala-tools.org/repo-releases/",
                     "http://nexus.scala-tools.org/content/repositories/snapshots/",
                     "http://repo.typesafe.com/typesafe/releases/"]
}

Passing multiple URLs to ‘mavenRepo’ has a very special meaning. (It’s a common pitfall, and that’s why we have changed the DSL in milestone-5). Change it to:

repositories {
    mavenCentral()
    mavenRepo urls: "http://repository.jboss.org/nexus/content/groups/public/"
    mavenRepo urls: "http://host/nexus/content/groups/public/"
    mavenRepo urls: "http://host/nexus/content/repositories/snapshots/"
    mavenRepo urls: "http://scala-tools.org/repo-releases/"
    mavenRepo urls: "http://nexus.scala-tools.org/content/repositories/snapshots/"
    mavenRepo urls: "http://repo.typesafe.com/typesafe/releases/"
}

This will very likely solve the problem.

hm… so it seems that with a repository list a POM is only looked up in the first repository entry. I see… well that was not so obvious :slight_smile:

Thanks Peter!

sugar was updated in M7 ( in case someone else has the problem ):

repositories {

mavenCentral()

maven { url ‘http://repository.jboss.org/nexus/content/groups/public/’ }

maven { url ‘http://scala-tools.org/repo-releases/’ }

maven { url ‘http://nexus.scala-tools.org/content/repositories/snapshots/’ }

maven { url ‘http://repo.typesafe.com/typesafe/releases/’ } }