java.lang.NoSuchMethodError for method that is not used

Viewed 1679

I'm pretty new to Maven and I'm having an issue with a NoSuchMethodError at runtime for a method that is not used anywhere in my project after merging my work with someone else's, particularly regarding com.google.inject.util.Types.collectionOf.

The new work has to do with fixing the project's executable jar, so I don't think any modifications had to do with guice. My local repo contains the exact same versions of the guice and multibinding jars as it did when I ran my previous version of this project and no obvious changes have been made to the pom files.

I am familiar with this kind of error and have fixed it before but this time I cannot figure out the issue. Here is the start of my error message:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.inject.util.Types.collectionOf(Ljava/lang/reflect/Type;)Ljava/lang/reflect/ParameterizedType;
    at com.google.inject.multibindings.Multibinder.collectionOfProvidersOf(Multibinder.java:202)
    at com.google.inject.multibindings.Multibinder$RealMultibinder.<init>(Multibinder.java:283)
    at com.google.inject.multibindings.Multibinder$RealMultibinder.<init>(Multibinder.java:258)
    at com.google.inject.multibindings.Multibinder.newRealSetBinder(Multibinder.java:178)
    at com.google.inject.multibindings.Multibinder.newSetBinder(Multibinder.java:132)
1 Answers

This question is old and already answered in comment, I was also facing same issue and base on comments, I did the things and my issue got resolved. So just to help other new users posting here.

When I was facing the issue, the my dependency in pom was as below.

<dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.0</version>
</dependency>

Now after adding one more dependency as below, it's got resolved and worked fine.

<dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-multibindings</artifactId>
        <version>4.0</version>
</dependency>
Related