Test task fails for java 1.8

I know that Java 1.8 is not officially released, but it is in developer preview. When I try to run gradle test (using testng) I get a “failed to read class file” exception, and the root stack is

Caused by: java.lang.IllegalArgumentException
 at org.objectweb.asm.ClassReader.<init>(Unknown Source)
 at org.objectweb.asm.ClassReader.<init>(Unknown Source)
 at org.objectweb.asm.ClassReader.<init>(Unknown Source)
 at org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector.classVisitor(AbstractTestFrameworkDetector.java:119)
 ... 105 more

Would like to know if there is a way around this. Thanks.

As a quick and dirty test, i downloaded asm-5.0-ALPHA and copied the asm-5.0.jar and asm-all-5.0.jar into GRADLE_HOME/lib (but renamed them to 4.0 to trick Gradle into thinking it had the correct dependencies) and the test task worked.

Can Gradle be updated to depend on asm-5.0 in order to better support development against Java 1.8?

note: i tried asm 4.1 too and it did not work for me.

We’ll likely update once ASM 5.0 final is out. Until then, you’ll need to run Gradle itself with Java 7, but can already compile with/against 8. We also have plans to make the it easier and more performant to compile with a Java version other than the one that Gradle is run with.

Thanks Peter. I configured our JavaCompile tasks to fork and point to java8. However, it’s a little tricky to change the Java version that Gradle runs with because it appears that Gradle only checks the JAVA_HOME environment variable or defaults to the system java, both of which we have set to Java8 JRE for reasons specific to our development environment and product.

I’m leaning towards modifying the gradle wrapper scripts that were generated to add a check for a GRADLE_JAVA_HOME environment variable and to use that if it is set.

Is there any other way to more easily configure a java version for Gradle that I might be missing?

Thanks.