6

A maven project consisting of some modules. One of my module is using guava dependency of google version 11.0.2. Now i am integrating another module in my project which is also using guava but version 14.

So i want that new module uses guava version 14 but remaining project use guava version 11.0.2. I have tried adding <exclusion></exclusion> of guava to the new module but it didn't work.

Any tips to solve this.

Update: @Guillaume Darmont's Answer solves the problem for different modules. but now my problem is, the new modules has 2 dependency one of the them is using guava 11.0.2 and other is using 14.0. how to manage this. can we specify separately in the pom of the module that which version of the guava it should use.?

Amol Sharma
  • 1,521
  • 7
  • 20
  • 40
  • I didn't fully understand your question. You are trying to use Guava `14` on both modules ? Also, do you use a common parent POM ? – Guillaume Darmont Jun 27 '13 at 06:16
  • i want to use guava 14 on the new module, which i am integrating. Older modules will be using guava 11.0.2 only. And yes i have a commmon parent POM. – Amol Sharma Jun 27 '13 at 06:22
  • Are you sure both 11.0.2 and 14 can coexist? In normal circumstances, only one of the libraries (appearing first in the classpath) will be used. – Kalpak Gadre Jun 27 '13 at 06:32

3 Answers3

6

As I understand your question, you may add a <dependencyManagement> for guava in your new module pom.xml :

<dependencyManagement>
  <dependencies>
      <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>14.0.1</version>
      </dependency>
  </dependencies>
</dependencyManagement>
saurav
  • 3,424
  • 1
  • 22
  • 33
Guillaume Darmont
  • 5,002
  • 1
  • 23
  • 35
  • Appreciate the answer. it works for the situation mentioned. is it possible to use different version of dependency in single module. i mean the new module has 2 dependency one of them is using guava `11.0.2` and `14.0`. how to manage this. – Amol Sharma Jun 27 '13 at 07:01
  • No, it is not possible. All classes in a Maven module share the same classpath. BTW to simply your dependencies, you should only have one version of guava for all the modules of your project. Guava 14 should be mostly (if not totaly) backwards compatible with version 11. – Guillaume Darmont Jun 27 '13 at 07:47
5

mvn dependency:tree command will help to determine which module is bringing the Guava 14 jar file.

Sean Connolly
  • 5,692
  • 7
  • 37
  • 74
user1573133
  • 904
  • 1
  • 9
  • 23
  • 2
    More specifically `mvn dependency:tree -Dverbose -Dincludes=com.google.guava` will display _just_ the parts of the dependency tree you're interested in, and include details about why a dependency was omitted (conflict/duplicate) in each case. [Apache Maven Project - Resolving conflicts using the dependency tree](http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html) – Sean Connolly Dec 06 '14 at 16:28
0

Firstly try mvn dependency tree and check the output it is possible that 11.0.2 has been transitively referenced from more than one of your projects dependencies and you will need to add exclusion to all the dependencies directly / indirectly pulling down the specific guava version you are trying to exclude.

Secondly resolving this conflict may not be straight forward. Looking at version number transition (11 to 14) sounds to me like a major transition, and you may have better chances keeping the 14 version and excluding the 11 something.

If the version change is not compatible with your application, you have pretty much no option but to use something like OSGi to ensure you can run different versions of same library in the project.

Kalpak Gadre
  • 6,285
  • 2
  • 24
  • 30