I have a maven project that uses springboot, and spring data cassandra which includes datastax's cassandra driver, which works fine.
When I introduce a 3rd library (let's call it new-library) dependency which shares a transitive dependency with the cassandra driver (com.typesafe:config), the driver throws a ClassNotFoundException for a class in that transitive dependency.
Now the dependency is the same version in the cassandra driver as the 3rd library.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>new-library</artifactId>
<version>1.0.0</version>
</dependency>
Without new-library, mvn dependency:tree shows com.typesafe:config:jar:1.4.1 showing up under the datastax driver.
+- org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.5.4:compile
| +- org.springframework:spring-tx:jar:5.3.9:compile
| \- org.springframework.data:spring-data-cassandra:jar:3.2.4:compile
| +- com.datastax.oss:java-driver-core:jar:4.11.3:compile
| +- com.typesafe:config:jar:1.4.1:compile
...
When I add in the new-library dependency, that vanishes from mvn tree but shows up under new-library.
\- com.example:new-library:jar:1.0.0:compile
+- com.typesafe:config:jar:1.4.1:compile
I've tried setting an exclusion in the new-library dependency - that did not work.
<exclusions>
<exclusion>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</exclusion>
</exclusions>
I also tried adding com.typesafe:config as a standalone dependency with and without scope set to runtime. That did not work.
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.1</version>
<scope>runtime</scope>
</dependency>
exception
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.datastax.oss.driver.api.core.config.DriverConfigLoader]: Factory method 'cassandraDriverConfigLoader' threw exception; nested exception is java.lang.NoClassDefFoundError: com/typesafe/config/ConfigOriginFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.9.jar:5.3.9]
... 198 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/typesafe/config/ConfigOriginFactory
at com.datastax.oss.driver.internal.core.config.typesafe.TypesafeDriverConfig.<clinit>(TypesafeDriverConfig.java:45) ~[java-driver-core-4.11.3.jar:na]
at com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader.<init>(DefaultDriverConfigLoader.java:196) ~[java-driver-core-4.11.3.jar:na]
at com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader.<init>(DefaultDriverConfigLoader.java:182) ~[java-driver-core-4.11.3.jar:na]
at com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder.build(DefaultProgrammaticDriverConfigLoaderBuilder.java:244) ~[java-driver-core-4.11.3.jar:na]
at org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration.cassandraDriverConfigLoader(CassandraAutoConfiguration.java:117) ~[spring-boot-autoconfigure-2.5.4.jar:2.5.4]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.9.jar:5.3.9]
Caused by: java.lang.ClassNotFoundException: com.typesafe.config.ConfigOriginFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na]
so it turns out the 3rd library was being built by a very old version of gradle. I upgrade gradle there and rebuilt and retried this project and the problem was resolved. I guess gradle created an invalid pom of some sort.