Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 748
confile Avatar asked Feb 10 '15 23:02

confile


People also ask

How do I force Gradle dependencies?

Simply open the gradle tab (can be located on the right) and right-click on the parent in the list (should be called "Android"), then select "Refresh dependencies". This should resolve your issue.

How do I override the dependency version of Child Gradle?

To override the version of a transitive dependency in Gradle, exclude it from the declared dependency that pulls it in, and then explicitly declare the version that you prefer to use in your build. gradle.

How do you resolve transitive dependencies in Gradle?

A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.

Can we have 2 build Gradle?

Hello , can i create multiple build. gradle for one project? Yes. You can have multiple build files in one project.


2 Answers

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'         }     } 
like image 126
cmcginty Avatar answered Sep 24 '22 09:09

cmcginty


configurations.all {   resolutionStrategy.eachDependency { details ->     if (details.requested.group == 'com.google.guava') {       details.useVersion "14.0.1"     }   } }  dependencies {   compile 'com.google.guava:guava'   compile 'com.google.guava:guava-gwt' } 
like image 31
Vyacheslav Shvets Avatar answered Sep 22 '22 09:09

Vyacheslav Shvets