How to resolve dependency conflicts with Gradle?

I am developing a project with Dropwizard and Titan DB. Both depend on Google Guava. One of them depends on version 15, and the other on 18. This error occurs at runtime:

! java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool$ID BlockRunnable 

I investigated the error and found that it is caused by the titanium Guava 15.0, which are being superseded by Guva 18.0.

I am new to Java and Gradle. I use Gradle java and application plugins to create and run the main class using gradle run . How can I solve this problem?


Here is my build.gradle :

 apply plugin: 'java' apply plugin: 'application' mainClassName = "com.example.rest.App" repositories { mavenCentral() } dependencies { compile ( [group: 'io.dropwizard', name: 'dropwizard-core', version: '0.8.0-rc1'], [group: 'com.thinkaurelius.titan', name: 'titan-core', version: '0.5.1'], [group: 'com.thinkaurelius.titan', name: 'titan-berkeleyje', version: '0.5.1'], [group: 'com.tinkerpop', name: 'frames', version: '2.6.0'] ) testCompile group: 'junit', name: 'junit', version: '3.8.1' } run { if ( project.hasProperty("appArgs") ) { args Eval.me(appArgs) } } 
+5
source share
1 answer

By default, Gradle will select the highest version for the dependency when there is a conflict. You can force the use of a specific version using a special permission strategy (adapted from http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html ):

 configurations.all { resolutionStrategy { force 'com.google.guava:guava:15.0' } } 

This does not add a dependency on guava 15.0, but says there is a dependency (even transitively) to force using 15.0.

You can get more information about where your dependencies appear with gradle dependencies and gradle dependencyInsight ...

FYI, it looks like you have several different versions of Guava requests (11.0.2, 14.0.1, 15.0 and 18.0).

NTN

+5
source

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


All Articles