DropWizard 0.9.1 support?
Closed this issue · 10 comments
Thanks for creating this library.
I tried to hack around the dependency conflicts between DropWizard-0.9.1 and DropWizard-Guice 0.8.x but didn't managed to succeed.
Is there a plan to release an updated that is compatible with the DropWizard 0.9 series?
Thanks
To work around the dependency conflicts, I excluded the obsolete Dropwizard dependencies pulled in by Dropwizard-Guice 0.8.4.0:
<dependency>
<groupId>com.hubspot.dropwizard</groupId>
<artifactId>dropwizard-guice</artifactId>
<version>0.8.4.0</version>
<exclusions>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jackson</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jersey</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jetty</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-lifecycle</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
</exclusion>
</exclusions>
</dependency>
also would like dropwizard 0.9.2 support. The exclusions above are not sufficient or do not work when using maven enforcer plugin.
Dependency convergence error for com.google.code.findbugs:annotations:3.0.0 paths to dependency are:
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-com.google.code.findbugs:annotations:3.0.0
and
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.reflections:reflections:0.9.9
+-com.google.code.findbugs:annotations:2.0.1
[WARNING]
Dependency convergence error for org.javassist:javassist:3.18.1-GA paths to dependency are:
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.glassfish.jersey.core:jersey-server:2.22.1
+-org.glassfish.hk2:hk2-locator:2.4.0-b31
+-org.javassist:javassist:3.18.1-GA
and
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.reflections:reflections:0.9.9
+-org.javassist:javassist:3.18.2-GA
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.google.code.findbugs:annotations:3.0.0 paths to dependency are:
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-com.google.code.findbugs:annotations:3.0.0
and
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.reflections:reflections:0.9.9
+-com.google.code.findbugs:annotations:2.0.1
,
Dependency convergence error for org.javassist:javassist:3.18.1-GA paths to dependency are:
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.glassfish.jersey.core:jersey-server:2.22.1
+-org.glassfish.hk2:hk2-locator:2.4.0-b31
+-org.javassist:javassist:3.18.1-GA
and
+-com.hubspot.dropwizard:dropwizard-guice:0.8.4.0
+-org.reflections:reflections:0.9.9
+-org.javassist:javassist:3.18.2-GA
I took a shot at this and could not get it to compile.
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Error injecting constructor, java.lang.IllegalStateException: java.lang.NoSuchFieldException: defaultGenerator
at com.hubspot.dropwizard.guice.HK2Linker.<init>(HK2Linker.java:17)
at com.hubspot.dropwizard.guice.JerseyModule.configureServlets(JerseyModule.java:23)
while locating com.hubspot.dropwizard.guice.HK2Linker
do not know enough about Jersey to get it to work, I use RestEasy outside Dropwizard.
I'm also interested in getting this working with more recent versions of Dropwizard.
Please do that
We are currently using dropwizard-guice-0.8.4
together with dropizward-0.9.2
.
In order to do so we set the following dependency management:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jetty</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jackson</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jersey</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-lifecycle</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>2.4.0-b31</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
<version>2.4.0-b31</version>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-healthchecks</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9</version>
</dependency>
</dependencies>
</dependencyManagement>
@phavelar I am working around those dependency conflicts by using the following additional exclusions :
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
Also, it would be amazing see support for Dropwizard 1.0.0 . It is currently not possible I believe because DW 1.0.0 has upgraded to Jersey 2.22.2, while dropwizard-guice still uses 2.22.1 ( and causes a conflict on hk2-api:jar:2.4.0-b34 and hk2-api:jar:2.4.0-b31 versions respectively. A simple exclusion rule here doesn't seem to work and results in the same exception mentioned by @jarrodhroberson above)
Off Topic
Hey because the documentation on DropWizard site does not explain how to do this. I just generated a gist that explains how to use Jersey's own DI in your application. As an alternative to Guice as your dependency management framework. https://gist.github.com/derekbassett/712698cd6424e5ff04da
I looked some more into this. The library https://github.com/Squarespace/jersey2-guice#getting-started, on which dropwizard-guice is based, explicitly warns that the startup may not be reliable:
Jersey/HK2 uses unfortunately SPIs and the Singleton pattern internally. Your code is effectively racing against the Servlet container's code and the first one to initialize HK2's ServiceLocatorGenerator inside its ServiceLocatorFactory wins.
This library uses two approaches to override HK2's own ServiceLocatorGenerator. It first tries to use a SPI and if it can't it'll fall back to reflection to replace a private static field. Regardless of the approach it's still a race against the Servlet container.
I believe they are referring to this method here : https://github.com/Squarespace/jersey2-guice/blob/master/jersey2-guice-impl/src/main/java/com/squarespace/jersey2/guice/JerseyGuiceUtils.java#L117
I tried making the following upgrades to dropwizard-guice
- Dropwizard 1.0.0-SNAPSHOT (from 0.8.4)
- jersey2-guice 1.0.6 (from 0.10)
- jersey-server 2.22.2 (from 2.21)
- hk2-api 2.4.0-b34 (from 2.4.0-b31)
(I've added the maven-enforcer plugin to ensure there's no DependencyConvergence errors)
All but 1 test pass (the failed test is https://github.com/HubSpot/dropwizard-guice/blob/4d079c98f026498ebc94e8514bd647b4c2c31f08/src/test/java/com/hubspot/dropwizard/guice/InjectedIntegrationTest.java). I'm unable to debug any further because of my limited knowledge of the Jersey and HK2 internals.
The changes are here : https://github.com/bladecatcher/dropwizard-guice
Having said that, the folks at https://github.com/gwizard/gwizard/tree/master/gwizard-jersey have this to say about jersey2-guice:
... because Jersey v2 and Guice do not play nice together. The courageous souls at Squarespace managed to create an adaptor, but it works by using reflection to punch values into private static final member data in Jersey. This module uses that adaptor; it works for the current version of Jersey, but it may not work for future versions of Jersey.
and they take the RESTEasy route, but obviously that's not an option for anyone using Dropwizard
I'd appreciate it if anyone with more knowledge on this matter can shed more light on the future of this approach.
I just pushed release 1.0.0 that uses dropwizard 1.0.0