Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError - Maven dependencies use different subdependencies

I have a problem in a project that uses has two dependencies. One to a third-party lib, which uses Guava 10.0.1, and one to mine, where I use Guava 14.0.1.
The problem now is, that there is a method in 10.0.1 which was deleted in 14.0.1 and conversly a class that was added after 10.0.1.
So I get either a NoSuchMethodError or an NoClassDefFoundError.
Is there any way around this?

like image 255
martin Avatar asked Nov 01 '22 11:11

martin


1 Answers

You can either use the older Guava version in your own project, or tell the third-party lib to use the newer version (and pray that that works).

You can use the maven exclude tag to make sure the third-party lib does not use it's own dependency version. Example:

<dependencies>
    <dependency>
      <groupId>third.party</groupId>
      <artifactId>lib</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>guava</groupId>
          <artifactId>guava</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
like image 81
gstandaert Avatar answered Nov 15 '22 04:11

gstandaert