I have a project that pulls in a shaded jar that contains guava (and without relocating the guava classes to a package of their own). When running gradle test I get an exception
java.lang.NoClassDefFoundError: Could not initialize class org.gradle.internal.SystemProperties
This class uses the of() method in a static initialization. I guess the duplicate guava classes have different classloaders causing the problem. Is there any way to solve this? Perhaps some way of untangling the gradle classpath and my own classpath? Spawning the tests in their own VM?
There shouldn’t be any conflict between your and Gradle’s Guava classes when running tests. Would you be able to provide a self-contained reproducible example?
Yes, actually the interaction is a bit more complex. We pull in guava and hive-exec is the shaded jar containing guava. It occurs with a simple module with the following
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '15.+'
compile group: 'org.apache.hive', name: 'hive-exec', version: '0.12.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Does your (main or test) code make use of ‘org.gradle.internal.SystemProperties’?
The problem shows up even with a simple empty test when running gradle test in combination with this build file
apply plugin: 'java'
sourceCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '15.+'
compile group: 'org.apache.hive', name: 'hive-exec', version: '0.12.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
import org.junit.Test;
public class TestCase {
@Test
public void test() {}
}
This passes with 1.7/1.8 but fails with 1.9. Could be related to our upgrade from ‘guava’ to ‘guava-jdk5:14.0.1’, which might have introduced a problem or surfaced an existing one. Raised GRADLE-2962. Thanks for reporting.
I had same problem. but it’s solved now.
remove guava dependency from hive.
compile(“org.apache.hive:hive-exec:0.12.0”) {
exclude group: ‘com.google.guava’ }
It occures same Array class used by gradle from 2 guava jars. So I think it’s not bug in gradle.