One of the dependencies declared in my project has a transitive dependency on 'com.google.guava:guava:15.0'
. But my application deployed on WAS/Weblogic doesn't work due to a CDI issue which has been fixed in 'com.google.guava:guava:15.0:cdi1.0'
. (same version, but with classifier) I need to tell gradle to use this jar during build and packaging. I am trying to figure on how we can ovrride this transitive dependency with a jar specific version classifier.
Tried the following approches:
compile 'com.google.guava:guava:15.0:cdi1.0'
. But both jars got included in the resultant WAR.Added the dependency explicitly and defined a resolution strategy:
configurations.all { resolutionStrategy { force 'com.google.guava:guava:15.0:cdi1.0' } }
Even this didn't work.
Defined a resolution strategy to check and change the version.
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> if (details.requested.group + ":" + details.requested.name == 'com.google.guava:guava') { details.useVersion "15.0:cdi1.0" //details.useTarget "com.google.guava:guava:15.0:cdi1.0" } } }
Even this didn't work.
Need your suggestions on how this issue can be tackled.
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.
How do you do this if the wrong dependency is a transitive dependency? By taking advantage of Maven's nearest definition logic, developers can override the version of a dependency by declaring it on the root pom. xml file.
When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com. google. guava:guava:30.1.
Gradle automatically resolves those additional modules, so called transitive dependencies. If needed, you can customize the behavior the handling of transitive dependencies to your project's requirements. Projects with tens or hundreds of declared dependencies can easily suffer from dependency hell.
Currently classifiers are not yet taken into account when it comes to resolutionStrategies. A workaround for you might excluding the transitive Guava library when declaring your dependencies and adding the Guava cdi1.0
version explicitly:
dependencies { compile ("org.acme:someDependency:1.0"){ exclude group: 'com.google.guava', module: 'guava' } compile "com.google.guava:guava:15.0:cdi1.0" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With