Gradle uses java6 compiler even with source compatability 1.7

(Sangeetha Karthik) #1


We are using gradle 1.12 for our java build. The problem is that in a particular machine, the build breaks, since gradle seems to use the java 6 compiler. The logs are shown below:

Gist link of the build failure:

(Peter Niederwieser) #2

By default, Gradle will compile with the same JDK that Gradle itself is run with, so perhaps that machine has JDK6 on its ‘PATH’, or has ‘JAVA_HOME’ pointing to JDK6. ‘gradle -v’ will tell.

PS: ‘jdk6.Jdk6JavaCompiler’ in the stack trace doesn’t mean that Gradle is compiling with JDK6. It just means that it is using the compiler API introduced in JDK6.

(Peter Niederwieser) #3

I should add that ‘sourceCompatibility’ doesn’t have any effect on which compiler/runtime library will be used. It just determines the language level used by the compiler.

(Sangeetha Karthik) #4

Thank you for the quick response. However, when we do print out the version of the JVM on the command prompt and JAVA_HOME, it all points to JDK 7. Furthermore, JDK 6 is not even installed in the system. See below Gist:

We’re pretty sure that whatever logs we have would not be sufficient to figure out the cause, but we appreciate the help nevertheless. In any case, is there a way that we can print out on the console the actual java command run by the build - that might throw up some pointers as to where the issue lies.

(Peter Niederwieser) #5

What counts is the Java version printed by ‘gradle -v’. If this prints “1.7.0” under “JVM”, then unless you’ve reconfigured ‘compileJava.options.forkOptions.executable’, JDK7 will be used for compilation. (If you’ve set ‘compileJava.options.fork = true’ or ‘compileJava.options.useAnt = true’, try to set both to ‘false’.) Running with ‘–info’ should print out the equivalent ‘javac’ command, however what’s really used is the Java compiler API.

(Sangeetha Karthik) #6

Thank you - that should be fine to try and get to the root cause.