rackerlabs / gradle-jaxb-plugin

Gradle plugin to ease projects that use xsds and the ant jaxb task
GNU General Public License v2.0
34 stars 21 forks source link

Guice dependency in conflict with some other plugin Guice #47

Open nemecec opened 4 years ago

nemecec commented 4 years ago

I added gradle-jaxb-plugin to my project and the build started failing with:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.Annotations
        at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:362)
        at com.google.inject.Key.strategyFor(Key.java:339)
        at com.google.inject.Key.get(Key.java:274)
        at com.google.inject.assistedinject.FactoryModuleBuilder.implement(FactoryModuleBuilder.java:266)
        at com.google.inject.assistedinject.FactoryModuleBuilder.implement(FactoryModuleBuilder.java:250)
        at com.google.inject.assistedinject.FactoryModuleBuilder.implement(FactoryModuleBuilder.java:242)
        at com.google.inject.assistedinject.FactoryModuleBuilder$implement.call(Unknown Source)
        at org.openrepose.gradle.plugins.jaxb.schema.guice.DocSlurperModule.configure(DocSlurperModule.groovy:44)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
        at com.google.inject.Guice.createInjector(Guice.java:94)
        at com.google.inject.Guice.createInjector(Guice.java:71)
        at com.google.inject.Guice$createInjector.call(Unknown Source)
        at org.openrepose.gradle.plugins.jaxb.JaxbPlugin.apply(JaxbPlugin.groovy:51)
        at org.openrepose.gradle.plugins.jaxb.JaxbPlugin.apply(JaxbPlugin.groovy)

The issue seems to be with the Guice library that is used by gradle-jaxb-plugin and ends up being pulled transitively into Gradle classpath (Gradle does not have separate classloaders for separate plugins). Judging by the stack trace, it is in conflict with Sonatype sisu-guice-3.1.0 library which probably comes from some Maven plugin (as Sonatype is the company behind Maven).

Solution: shadow the Guice library, pull it into gradle-jaxb-plugin namespace.