Travis CI: Update config to handle cross-compilation

This commit is contained in:
str4d
2019-02-17 02:33:19 +00:00
parent 9731c203bd
commit 2556c7755b
2 changed files with 50 additions and 7 deletions

View File

@@ -40,6 +40,15 @@ String compat(String src) {
}
}
String javaExecutable(String targetJavaHome, String execName) {
def javaExecutablesPath = new File(targetJavaHome, "bin")
def executable = new File(javaExecutablesPath, execName)
if (!executable.exists()) {
throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
}
executable.toString()
}
def releaseVersion = getReleaseVersion()
def buildVersion = getBuildVersion()
def buildExtra = getBuildExtra()
@@ -98,6 +107,36 @@ configure(javaProjects) {
options.compilerArgs.addAll(['--release', version])
}
}
// Set up Java override if configured (used to test with Java 7).
def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
if (targetJavaHome) {
if (JavaVersion.current().java9Compatible) {
throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
}
project.afterEvaluate {
logger.info("Target Java home set to ${targetJavaHome}")
logger.info("Configuring Gradle to use forked compilation and testing")
tasks.withType(JavaCompile) {
options.fork = true
options.forkOptions.javaHome = file(targetJavaHome)
}
tasks.withType(Javadoc) {
executable = javaExecutable(targetJavaHome, "javadoc")
}
tasks.withType(Test) {
executable = javaExecutable(targetJavaHome, "java")
}
tasks.withType(JavaExec) {
executable = javaExecutable(targetJavaHome, "java")
}
}
}
}
task codeCoverageReport(type: JacocoReport) {