-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjdks.gradle
38 lines (37 loc) · 1.24 KB
/
jdks.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
String compat(String src) {
if (src.contains('.')) {
src.substring(src.lastIndexOf('.')+1)
} else {
src
}
}
if (project.hasProperty('crossCompile')) {
// this will configure the java compile tasks with the appropriate JDK
project.afterEvaluate {
tasks.withType(JavaCompile) {
def version = compat(sourceCompatibility)
def jdkHome = System.getenv("JAVA_${version}")
if (!jdkHome) {
println "Warning: Please set path to JDK ${version} using environment variable JAVA_${version}"
println "Falling back to current JDK"
} else {
options.fork = true
options.forkOptions.javaHome = file(jdkHome)
doFirst {
println "$name compiles using JDK $version"
}
}
}
}
} else {
if (!JavaVersion.current().java9Compatible) {
throw new GradleException("You must use -PcrossCompile to enable cross compilation, or run Gradle with JDK 9")
}
project.afterEvaluate {
tasks.withType(JavaCompile) {
def version = compat(sourceCompatibility)
println "Configuring $name to use --release $version"
options.compilerArgs.addAll(['--release', version])
}
}
}