Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

java.lang.NoClassDefFoundError: com/google/gson/JsonElement after updating to version 2.3.4. #105

Closed
brettcooper opened this issue Nov 14, 2017 · 3 comments

Comments

@brettcooper
Copy link

brettcooper commented Nov 14, 2017

We are using the LaunchDarkly Java client and when upgrading from version 2.3.3 to 2.3.4, the com.google.code.gson dependency is now missing at runtime. We receive the following error when trying to initialize the LDClient:

1) Error injecting constructor, java.lang.NoClassDefFoundError: com/google/gson/JsonElement
at com.unific.aws.config.launchdarkly.LaunchDarklyClientProvider.<init>(LaunchDarklyClientProvider.java:21)
while locating com.unific.aws.config.launchdarkly.LaunchDarklyClientProvider
at com.unific.aws.config.ConfigurationModule.configure(ConfigurationModule.java:21)
while locating com.launchdarkly.client.LDClient
for the 1st parameter of com.unific.aws.config.ConfigurationProvider.<init>(ConfigurationProvider.java:30)
while locating com.unific.aws.config.ConfigurationProvider
at com.unific.aws.config.ConfigurationModule.configure(ConfigurationModule.java:22)
while locating com.unific.aws.config.Configuration
for the 6th parameter of com.unific.graphql.services.CampaignService.<init>(CampaignService.java:68)
while locating com.unific.graphql.services.CampaignService
while locating com.unific.graphql.services.GraphQLService annotated with @com.google.inject.multibindings.Element(setName=,uniqueId=3, type=MULTIBINDER, keyType=)
at com.unific.graphql.guice.GraphQLModule.configure(GraphQLModule.java:60) (via modules: com.unific.graphql.guice.GraphQLModule -> com.google.inject.multibindings.Multibinder$RealMultibinder)
while locating java.util.Set<com.unific.graphql.services.GraphQLService>
for the 1st parameter of com.unific.graphql.guice.GraphQLSchemaProvider.<init>(GraphQLSchemaProvider.java:25)
while locating com.unific.graphql.guice.GraphQLSchemaProvider
at com.unific.graphql.guice.GraphQLModule.configure(GraphQLModule.java:34)
while locating graphql.schema.GraphQLSchema
for the 1st parameter of com.unific.graphql.guice.GraphQLProvider.<init>(GraphQLProvider.java:20)
while locating com.unific.graphql.guice.GraphQLProvider
at com.unific.graphql.guice.GraphQLModule.configure(GraphQLModule.java:35)
while locating graphql.GraphQL
for the 1st parameter of com.unific.graphql.GraphQLExecutor.<init>(GraphQLExecutor.java:22)
at com.unific.graphql.guice.GraphQLModule.configure(GraphQLModule.java:52)
while locating com.unific.graphql.GraphQLExecutor

1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:99)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.unific.graphql.guice.GraphQLInjector.<clinit>(GraphQLInjector.java:23)
... 5 more
Caused by: java.lang.NoClassDefFoundError: com/google/gson/JsonElement
at com.unific.aws.config.launchdarkly.LaunchDarklyClientProvider.<init>(LaunchDarklyClientProvider.java:26)
at com.unific.aws.config.launchdarkly.LaunchDarklyClientProvider$$FastClassByGuice$$68d9c580.newInstance(<generated>)
at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
at com.google.inject.multibindings.Multibinder$RealMultibinder.get(Multibinder.java:375)
at com.google.inject.multibindings.Multibinder$RealMultibinder.get(Multibinder.java:258)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.google.gson.JsonElement
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 85 more

Also, we tried including the <classifer>all</classifer> within the LaunchDarkly maven dependency config and that broke other dependencies with log4j or slf4j. In the meantime we have rolled back to version 2.3.3 of the LaunchDarkly client.

@brettcooper brettcooper changed the title Google Gson not included in shaded jar for version 2.3.4. java.lang.NoClassDefFoundError: com/google/gson/JsonElement after updating to version 2.3.4. Nov 14, 2017
@pkaeding
Copy link
Contributor

Hi @brettcooper

We removed Gson from the default jar as a result of #103 . It should be pulled in as a dependency, as it is listed with a compile scope in the pom file, though. Can you share your pom file, or at least the parts that reference LaunchDarkly or Gson? If you'd rather not share it publicly on github, you can email [email protected] and we can take it from there.

@brettcooper
Copy link
Author

brettcooper commented Nov 15, 2017

Hi @pkaeding

Thanks for the quick reply! Here is the LaunchDarkly dependency from our project:

        <!-- Feature Hiding -->
        <dependency>
            <groupId>com.launchdarkly</groupId>
            <artifactId>launchdarkly-client</artifactId>
            <!-- Don't upgrade to version 2.3.4 until LaunchDarkly re-includes the gson libarary in their shaded jar -->
            <!-- https://github.com/launchdarkly/java-client/issues/105 -->
            <version>2.3.3</version>
            <!-- added for dependency convergence -->
            <exclusions>
                <!-- com.amazonaws:aws-java-sdk-core specifies joda-time -->
                <exclusion>
                    <groupId>joda-time</groupId>
                    <artifactId>joda-time</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Here are the references to gson from our parent pom:

<properties>
    <gson.version>2.7</gson.version>
</properties

<dependencyManagement>
    <dependencies>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>${gson.version}</version>
            </dependency>
    </dependencies>
<dependencyManagement/>

<dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <scope>test</scope>
        </dependency>
</dependency>

Please let me know if this is enough info, or I can email [email protected] with our full pom's. Thanks for your help!

@brettcooper
Copy link
Author

brettcooper commented Nov 15, 2017

Ok, I fixed this now by removing the test scope for gson in our parent pom.

<dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
</dependency>

Thanks for your help with this issue!

eli-darkly added a commit that referenced this issue Nov 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants