[GRADLE-2962] Test execution failure when duplicate Guava classes on test classpath Created: 26/Nov/13  Updated: 25/Mar/14  Resolved: 21/Mar/14

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.12-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Luke Daley
Resolution: Fixed Votes: 11


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?

Comment by Gradle Forums [ 26/Nov/13 ]

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?

Comment by Gradle Forums [ 26/Nov/13 ]

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'

Comment by Gradle Forums [ 26/Nov/13 ]

Does your (main or test) code make use of `org.gradle.internal.SystemProperties`?

Comment by Gradle Forums [ 26/Nov/13 ]

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 {

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 {
public void test() {}

Comment by Konrad Jamrozik [ 30/Nov/13 ]

I had a the same exception when running the test task of groovy plugin. Removing guava 15.0 from the classpath of the test task solved the problem for me as a temporary workaround.

My workaround snippet
project(":projectName") {

  apply plugin: 'groovy'


    Workaround for: http://issues.gradle.org/browse/GRADLE-2962
    Last reviewed on 1 Dec 2013.
  test.doFirst {
    classpath -= fileTree(dir: "$dirWithGuavaJar", include: "guava*.jar")

Please note that the workaround causes fallback to guava used by gradle 1.9, that is, 14.0.1 (source: Gradle Forums topic; link above). You cannot use newer version of Guava using this workaround.

Comment by Sebastien Tardif [ 19/Feb/14 ]

This bug was confirmed as a regression:
Peter Niederwieser (Core Dev):
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.

Should this issue be fixed faster than others because it's a regression? I see that it's not assigned to anyone. I think the bug tracker should have the flag "regression" and mention version introducing issues.

Comment by Jasdeep Hundal [ 10/Mar/14 ]

I've noticed issues with duplicate guava classes in versions prior to 1.10 as well (for example: this function being present in Guava 12 and onwards, which causes exceptions when gradle 1.8 loads guava 11: https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/base/Objects.java#219). This issue could just be manifesting in more ways with the update to guava-jdk5.

That being said, I'm currently running off gradle 1.10 and hurting everywhere when trying to use libraries that depend on the latest versions of Guava. If there's a good way to exclude specific versions of packages at runtime, I would love to know it. A quick peek into the source code suggests this might not be the case: https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/process/internal/child/WorkerProcessClassPathProvider.java#L69

Generated at Wed Jun 30 12:36:07 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.