Below is the content of the build.gradle file:
apply plugin: \'java\'
archivesBaseName = \'foo-bar\'
version = \'1.0\'
sourc
Rudik's answer needs a small modification to work with Gradle 2.0 and above: The "Compile" property must be changed to "JavaCompile." See: After upgrading to Gradle 2.0: Could not find property 'Compile' on root project
I ran into the original poster's problem on Android Studio 2.2.2 (JDK8) compiling for Google App Engine (Java 7). Here is Rudik's answer accordingly modified to fix this scenario:
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.bootClasspath = "$JDK7_HOME/jre/lib/rt.jar"
}
And again in gradle.properties, add whatever your path is to the JDK, e.g. for Mac
JDK7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
Thanks again to Rudik for posting the original answer. I wanted to add a comment instead of creating a new answer, but did not have enough reputation points (yet).
See the javac docs on cross compilation for details but basically it means you can compile against jdk classes that don't exist, or were different, on your target version. For example perhaps you use java.util.Deque
but are targeting jdk5.
I don't believe gradle has built in support for setting this. I have found that you need to twiddle the compile task manually. For example
def bootClasspathStr = "${yourJavaVersionXInstallationPath}/jre/lib/rt.jar"
project.tasks.withType(AbstractCompile, { AbstractCompile ac ->
ac.options.bootClasspath = bootClasspathStr // options is always there but not defined on AbstractCompile so going to hit it anyway
})
Having said all that, you appear to be building on jdk6 for java6 so I would think you can safely ignore the warning. Are you sure gradle is running under jdk6 and not 7?
You can bootstrap class path using bootClasspath option:
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
compileJava.options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar"
To set the bootClasspath option on all compile tasks in the project you can use the withType() method on the TaskContainer to find all tasks of type Compile:
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
tasks.withType(JavaCompile) {
options.bootstrapClasspath = files("$JDK6_HOME/jre/lib/rt.jar")
}
gradle.properties:
JDK6_HOME=C:/JAVA/jdk6
See documentation for details.
The solution to define the JVM for gradle at workspace level is not ideal. In the case of multiple projects/builds on different JVMs, this cannot be used.
In Eclipse Kepler with Spring Gradle plugin (3.3.0) it is possible to define the JVM for your gradle build task (External tool).
At External Tool Configuration | Arguments | Java Home you can define which JVM should be used for the build.