Gradle A transitive dependency exception is not working properly. (How to get rid of com.google.guava: guava-jdk5: 13.0?)

Here is a snippet of my build.gradle:

compile 'com.google.api-client:google-api-client:1.19.0' compile 'com.google.apis:google-api-services-oauth2:v2-rev77-1.19.0' compile 'com.google.apis:google-api-services-plus:v1-rev155-1.19.0' compile 'com.google.appengine.tools:appengine-gcs-client:0.4.1' compile 'com.google.appengine.tools:appengine-mapreduce:0.8' 

which imports several versions of guava, as you can see with dependencyInsight:

 com.google.guava:guava:15.0 (conflict resolution) com.google.guava:guava:14.0.1 -> 15.0 +--- com.googlecode.objectify:objectify:4.1.3 | \--- default \--- net.eusashead.spring:spring-cache-gae:1.0.0.RELEASE \--- default com.google.guava:guava:[15.0,15.99] -> 15.0 +--- com.google.appengine.tools:appengine-gcs-client:0.4.1 | +--- default | +--- com.google.appengine.tools:appengine-mapreduce:0.8 | | \--- default | \--- com.google.appengine.tools:appengine-pipeline:0.2.10 | \--- com.google.appengine.tools:appengine-mapreduce:0.8 (*) +--- com.google.appengine.tools:appengine-mapreduce:0.8 (*) \--- com.google.appengine.tools:appengine-pipeline:0.2.10 (*) com.google.guava:guava-jdk5:13.0 \--- com.google.api-client:google-api-client:1.19.0 +--- default +--- com.google.apis:google-api-services-oauth2:v2-rev77-1.19.0 | \--- default +--- com.google.apis:google-api-services-plus:v1-rev155-1.19.0 | \--- default +--- com.google.appengine.tools:appengine-gcs-client:0.4.1 | +--- default | +--- com.google.appengine.tools:appengine-mapreduce:0.8 | | \--- default | \--- com.google.appengine.tools:appengine-pipeline:0.2.10 | \--- com.google.appengine.tools:appengine-mapreduce:0.8 (*) +--- com.google.api-client:google-api-client-appengine:1.17.0-rc | \--- com.google.appengine.tools:appengine-gcs-client:0.4.1 (*) +--- com.google.apis:google-api-services-storage:v1-rev1-1.18.0-rc | \--- com.google.appengine.tools:appengine-gcs-client:0.4.1 (*) +--- com.google.apis:google-api-services-bigquery:v2-rev154-1.19.0 | \--- com.google.appengine.tools:appengine-mapreduce:0.8 (*) \--- com.google.api-client:google-api-client-servlet:1.17.0-rc \--- com.google.api-client:google-api-client-appengine:1.17.0-rc (*) (*) - dependencies omitted (listed previously) 

I tried to remove the dependency by doing:

 compile ('com.google.api-client:google-api-client:1.19.0'){ exclude group: 'com.google.guava', module: 'guava-jdk5' } compile ('com.google.api-client:google-api-client:1.19.0'){ exclude group: 'com.google.guava', } 

but the value of dependencyInsight remains unchanged. I also tried

 compile ('com.google.guava:guava:15.0'){force = true} 

but again the understanding of dependencies remains unchanged. How to get rid of com.google.guava: guava-jdk5: 13.0?

More: I tried gradle 1.2 and 2.1 in a Windows 8.1 window

The reason for this is getting rid of this exception:

 java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch; 
+6
source share
3 answers

It turns out that guava-jdk5 is still supported.

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 to fix my problems, now I can use the classes from the com.google.common package in the Google App Engine project with all the dependencies described

+3
source

It seems that the dependency will not be ruled out if there is somewhere else a dependency that points to the same dependency without any exceptions.

However, you can eliminate the dependency via configuration :

 configurations { all*.exclude group: 'com.google.guava', module:'guava-jdk5' } 
+16
source

Based on @thoutbeckers, they answer because of a special case where I did not think that his answer was applied, but it really is. Hope this answer can help others who share my problem with a specific case. Initially, I thought that only one dependency in the build.gradle file referred to a bad transitive dependency, but two dependencies actually referred to it. This is due to the fact that in both dependencies, in which a negative transitive dependence was indicated, there were parent / child relations, but I noticed only the relationship with the child dependence, and not the dependence on the parent.

Consider the following dependency tree (created by the gradle <my-project-name>:dependencies command):

 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 

In the dependency tree, it looks like other.org:bad.transitive:dependency:0.9.1 refers to only one dependency in your assembly 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, although the transitive dependency you wanted to exclude only occurs in the dependencies between the children and not on the parent dependency. However, since both the parent and the child projects reference the build.gradle file, a bad transitive dependency should be excluded from both dependencies, as indicated above.

Note that if you do not want to add an exception at the configuration level (as shown in @thoutbeckers answer), you can always simply exclude the transitive dependency on both dependencies where it is indicated, explicitly.

+3
source

Source: https://habr.com/ru/post/975144/


All Articles