How to build with JDK 7 target?

(Josh) #1

We have the following settings: in user home: (we have to use 8 as of some plugins we use)
build.gradle: sourceCompatibility = 1.7 targetCompatibility = 1.7

So gradle runs with a JDK 8 and supposed to build with compatibility 7. At least that’s what we thought. Now if you use a Method from a java8 api like list.sort(..) the build won’t crash although I use the targets 1.7

What do we miss? :slight_smile:

(Stefan Wolf) #2

Hi Josh,

you are only setting sourceCompatibility and targetCompatibility but you are still compiling with Java 8. You would need to set the bootClasspath on CompileOptions to a Java 7 JDK, too.
Another option would be to compile with a Java 7 javac like described in the userguide for Java 6. Note that this has quite a performance impact since Gradle will not be able to reuse the compiler daemons.


(Josh) #3

That works, thank you!

(Martin Vysny) #4

I’m sorry but I fail to see in the userguide what command-line parameters should I pass to gradle to use JDK8 for itself, while using JDK7 to perform the compilation. Would you please show the command line example here?