Plugin compiled with Java 8 won't work on Java 7

Hi, I’m the creator of the plugin https://github.com/JCAndKSolutions/android-unit-test/ And I compile it with Java 8 with the sourceCompatibility and TargetCompatibility set to 1.6. Everything was working perfectly until today when I got a failed Travis build: https://travis-ci.org/JCAndKSolutions/android-unit-test/jobs/44274091 . The stack trace says that the Class java.util.HashMap$Node was not found.

I extend a HashMap in my code but I don’t use the Node class directly. If I compile it with Java 7 it works. I use Gradle version 2.2.1 and use “compile localGroovy()” to reference the Groovy SDK. I don’t know if that has anything to do. Any ideas why is it hardcoding the Java 8 HashMap implementation? Would making my Map a .java instead of a .groovy help? Do I need to force a version of groovy?

I need to fix this ASAP since the version 2.1.0 is already in Maven central and I require to publish a fixed 2.1.1 for my users.

Thank you very much.

Jürgen.

Hi, 

I’m pretty sure this is a Groovy problem, that we won’t be able to resolve. Can you please provide a full stacktrace (obtained by running with ‘-S’, not ‘-s’) so we can verify?

I was able to fix this by not extending nor implementing the Map interface. I made a wrapper instead with a map as a member. So basically yeah, referencing any class that was touched in Java 8 can give trouble. It might be a groovy issue but correct me if I’m wrong, if use the ‘sourceCompatibility’, ‘targetCompatibility’ and ‘options.bootClasspath’ all pointing to Java 7, shouldn’t the byte code generated by compatible with Java 7 and not reference Java 8 classes/methods? this is what I have in build.gradle:

‘’’ compileJava {

sourceCompatibility = JavaVersion.VERSION_1_7

targetCompatibility = JavaVersion.VERSION_1_7

options.bootClasspath = “${System.env.JDK7_HOME}/jre/lib/rt.jar”

}

compileTestJava {

sourceCompatibility = JavaVersion.VERSION_1_7

targetCompatibility = JavaVersion.VERSION_1_7

options.bootClasspath = “${System.env.JDK7_HOME}/jre/lib/rt.jar”

}

compileGroovy {

sourceCompatibility = JavaVersion.VERSION_1_7

targetCompatibility = JavaVersion.VERSION_1_7

options.bootClasspath = “${System.env.JDK7_HOME}/jre/lib/rt.jar”

}

compileTestGroovy {

sourceCompatibility = JavaVersion.VERSION_1_7

targetCompatibility = JavaVersion.VERSION_1_7

options.bootClasspath = “${System.env.JDK7_HOME}/jre/lib/rt.jar”

}

test {

jvmArgs ‘-noverify’

} ‘’’

Notice the noverify flag that I have to set because otherwise the tests fail with a verification error. I’m completely lost as to what gradle does internally to compile and run with Java 8 JDK but keeping Java 7 compatible if that happens at all. Maybe Groovy is adding a dependency on Java 8?

Thanks for looking into this, I’ll see if I can get you the stack trace.