lundi 28 septembre 2015

Why my Spock unit tests fail in Gradle build after upgrading to JDK 8?

I'm trying to compile my application source using JDK 8, Groovy 2.4.4, Spock 1.0-groovy-2.4, Gradle 1.11 (my firm hass custom plugins built on top of this)

gradle -version
Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_51 (Oracle Corporation 24.51-b03)
OS:           Windows 7 6.1 amd64

In my build environment, I need to retain my JAVA_HOME to Java 7 for other projects.

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_51
JAVA8_HOME = C:\Program Files\Java\jdk1.8.0_60

Due to this, in my build.gradle, I explicitly tell Gradle to use JDK 8

tasks.withType(JavaCompile) {
    options.fork = true;
    options.forkOptions.executable = "${System.env.JAVA8_HOME}/bin/javac"
}

tasks.withType(Test) {
    executable = "${System.env.JAVA8_HOME}/bin/java"
}

compileJava{
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

The source files compile successfully, however when it reached unit tests (written in Spock), it fails with the below error.

Caused by: java.lang.UnsupportedClassVersionError: org/model/SDA : Unsupported major.minor version 52.0

I confirmed that SDA.class is compiled using JDK 8.

javap -verbose SDA.class | findstr "major"
  major version: 52

Any reason why only during unit tests I get the above error? Does that mean unit test is being run on JDK 7?

Aucun commentaire:

Enregistrer un commentaire