How can I force Gradle to set the same version for two dependencies?

confile picture confile · Feb 11, 2015 · Viewed 89.3k times · Source

I use the following two dependencies:

compile 'com.google.guava:guava:14.0.1'
compile 'com.google.guava:guava-gwt:14.0.1'

Both must be the same version to work correctly. Since my other dependencies use a higher version, Gradle uses different versions for each dependency.

I found this by running gradle dependencies:

compile - Compile classpath for source set 'main'.
+--- com.google.guava:guava:14.0.1 -> 17.0
+--- com.google.guava:guava-gwt:14.0.1
|    +--- com.google.code.findbugs:jsr305:1.3.9
|    \--- com.google.guava:guava:14.0.1 -> 17.0 

How can I force Gradle to set the same version for these two dependencies?

Answer

cmcginty picture cmcginty · Feb 11, 2015

Add this section to dependencies.gradle file

configurations.all {
        resolutionStrategy { 
            force 'com.google.guava:guava:14.0.1'
            force 'com.google.guava:guava-gwt:14.0.1'
        }
    }