Gradle Transitive dependency exclusion is not working as expected. (How do I get rid of com.google.guava:guava-jdk5:13.0 ?)
It seems a dependency will not be excluded if there is another dependency somewhere that points to that same dependency without any of the excludes.
You can exclude a dependency through configuration
however:
configurations {
all*.exclude group: 'com.google.guava', module:'guava-jdk5'
}
Building on @thoutbeckers answer due to a special case, where I didn't think that his answer applied, but it actually did. Hopefully, this answer can help others who shared my special case problem. Originally I thought that the bad transitive dependency was only referenced by one dependency in the build.gradle
file but it was actually referenced by two dependencies. This was because both dependencies where the the bad transitive dependency was referenced from had a parent/child relationship, but I only noticed the relationship with the child dependency, and not the parent dependency.
Consider the following dependency tree (produced by the command gradle <my-project-name>:dependencies
):
compileClasspath - Compile classpath for source set 'main'.
+--- my.org:com.my.pkg.parent:6.+ -> 6.0.4
| +--- # misc. dependencies
| +--- my.org:com.my.pkg.child:6.0.4
| | +--- # misc. dependencies
| | +--- other.org:bad.transitive.dependency:0.9.1 FAILED
| | +--- # misc. dependencies
| |--- # misc. dependencies
+--- # misc. dependencies
From the dependency tree, it looks like the other.org:bad.transitive:dependency:0.9.1
is only referenced by one dependency in your build file, not two. However, suppose your Gradle file looks like this:
// ... misc. ...
dependencies {
// ... misc. dependencies ...
compile 'my.org:com.my.pkg.parent:6.+'
// ... misc. dependencies ...
compile ('my.org:com.my.pkg.child:6.0.4') {
exclude group: 'other.org', module: 'bad.transitive.dependency'
}
For a Gradle file like the one above, the error will persist even though the transitive dependency you wanted to exclude occurs only in the child dependency, not the parent dependency. However, because both the parent and child projects are referenced by the build.gradle
file, the bad transitive dependency must be excluded from both dependencies, as @thoutbeckers stated above.
Note that if you don't want to add the exclusion at the configuration level (as @thoutbeckers showed in their answer), you can always just exclude the transitive dependency from both dependencies where it is referenced, explicitly.
It turns out that guava-jdk5 is still being maintained.
So I changed this:
compile ('com.google.guava:guava:15.0'){force = true}
for this:
compile('com.google.guava:guava-jdk5:17.0') { force = true }
And that fixed my issues, I can now use classes from the 'com.google.common' package in Google App Engine project with all the described dependencies