Hi All :gradlephant:,
I have a project (multi-project actually) that gets built for different JRE versions. Same code (mostly) needs to be built for 1.6, 1.7, and 1.8.
Right now this is accomplished by calling gradle multiple times, once for each target. The target is specified by a build property. The bootClasspath is set to use the correct jars based on the property, see below.
This works okay… but I am wondering if there is a better way. Not every invocation needs to build all variants, most of the time only 1 is needed. CI need to build all variants, so which targets get built needs to be configurable…
Is it possible to build for each desired target variant in a single Gradle invocation?
How would that be accomplished?
sourceCompatibility = project.targetJRE
targetCompatibility = project.targetJRE
// Set the classpath to use the correct JARs for building
tasks.withType(JavaCompile) {
doFirst {
options.encoding = 'UTF8'
switch (targetCompatibility.toString()) {
case '1.6':
options.bootClasspath = rootProject.file("jre/bootstrap/1.6/rt.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/bootstrap/1.6/plugin.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/ext/1.6/jaccess.jar")
break
case '1.7':
options.bootClasspath = rootProject.file("jre/bootstrap/1.7/rt.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/bootstrap/1.7/plugin.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/ext/1.7/jaccess.jar")
break
case '1.8':
default:
options.bootClasspath = rootProject.file("jre/bootstrap/1.8/rt.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/bootstrap/1.8/plugin.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/ext/1.8/jaccess.jar")
options.bootClasspath += File.pathSeparator + rootProject.file("jre/bootstrap/1.8/jce.jar")
break
}
}
}
thanks,