Lambda expressions coming with Java 8 are really great. Having played around with them I decided to migrate my current JavaFX projects and apply lambda expressions where it makes sense. In my IDE (IntelliJ IDEA) all worked fine but when I ran my gradle (1.7) build a weird message appeared:
Execution failed for task ':test'.
> failed to read class file ...../build/classes/test/MainTest.class
It turns out that the way gradle is scanning for class files to find out which ones are test classes causes the problem. Most likely due to different bytecodes produced by the Java 8 compiler.
Fortunately the scanning process can be turned off as described in gradle’s documentation. Then you just have to configure your test classes manually as in the following example and everything works again.
sourceCompatibility = '1.8'
test.scanForTestClasses = false // see http://forums.gradle.org/gradle/topics/1_7_rc_1_fails_to_read_classfile_for_test_when_using_java_8_0_ea_b99
exclude '**/*$*.class' // exclude anonymous inner classes
- Sven Ehrke, @syendar