Why doesn't Gradle include transitive dependencies in the compilation / runtime path?

I am learning how Gradle works, and I cannot understand how it solves the transitive dependencies of a project.

At the moment I have two projects:

  • projectA: which has a couple of dependencies on external libraries
  • projectB: which has only one dependency on projectA

No matter how I try, when I create projectB, Gradle does not include the projectA dependencies (X and Y) in the projectpro or runtime compilation path. I managed to get it working by including projectA dependencies in the projectB build script, which in my opinion makes no sense. These dependencies should automatically join projectB. I am pretty sure that I am missing something, but I cannot understand that.

I read about "lib dependencies", but it seems that this applies only to local projects, such as described here , and not to external dependencies.

Here is the build.gradle example that I use in the root project (the one that contains both projectA and projectB):

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.3' } } subprojects { apply plugin: 'java' apply plugin: 'idea' group = 'com.company' repositories { mavenCentral() add(new org.apache.ivy.plugins.resolver.SshResolver()) { name = 'customRepo' addIvyPattern "ssh://.../repository/[organization]/[module]/[revision]/[module].xml" addArtifactPattern "ssh://.../[organization]/[module]/[revision]/[module](-[classifier]).[ext]" } } sourceSets { main { java { srcDir 'src/' } } } idea.module { downloadSources = true } // task that create sources jar task sourceJar(type: Jar) { from sourceSets.main.java classifier 'sources' } // Publishing configuration uploadArchives { repositories { add project.repositories.customRepo } } artifacts { archives(sourceJar) { name "$name-sources" type 'source' builtBy sourceJar } } } 

This only applies to project A:

 version = '1.0' dependencies { compile 'com.company:X:1.0' compile 'com.company:B:1.0' } 

And this is the one used by projectB:

 version = '1.0' dependencies { compile ('com.company:projectA:1.0') { transitive = true } } 

Thanks in advance for any help and apologize for my poor English.

+7
source share
2 answers

Finally, the problem did not come from scripts. I just cleared the gradle cache and every project build folder to make this work.

+1
source

Put the following line depending on the project.

compile the project (': projectA')

+1
source

All Articles