I am implementing an API wrapper in Java 1.8 using Jersey 2.27. When I run an Invocation.Builder.get(), I get the following error:
Exception in thread "main" java.lang.IllegalStateException: InjectionManagerFactory not found.
at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
...
Following the guidance here, I update my Maven pom.xml file with the following dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
Now, when I compile using Maven, I get the following warning:
[WARNING] javax.inject-1.jar, javax.inject-2.5.0-b42.jar define 6 overlappping classes:
[WARNING] - javax.inject.Inject
[WARNING] - javax.inject.Singleton
[WARNING] - javax.inject.Scope
[WARNING] - javax.inject.Named
[WARNING] - javax.inject.Provider
[WARNING] - javax.inject.Qualifier
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin
From mvn dependency:tree
I can see that the two dependencies I showed above are causing this collision (I highlighted the lines in question):
[INFO] +- org.glassfish.jersey.core:jersey-client:jar:2.27:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:2.27:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
>> [INFO] | \- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b42:compile
[INFO] +- org.glassfish.jersey.inject:jersey-hk2:jar:2.27:compile
[INFO] | \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:compile
[INFO] | +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42:compile
[INFO] | +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:compile
>> [INFO] | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:compile
[INFO] | \- org.javassist:javassist:jar:3.22.0-CR2:compile
Why are these two dependencies, that should theoretically be updated together, causing this collision?