Changeset 2556c77 for build.gradle


Ignore:
Timestamp:
Feb 17, 2019 2:33:19 AM (14 months ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
4f6b58e
Parents:
9731c20
Message:

Travis CI: Update config to handle cross-compilation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • build.gradle

    r9731c20 r2556c77  
    3939        src
    4040    }
     41}
     42
     43String javaExecutable(String targetJavaHome, String execName) {
     44    def javaExecutablesPath = new File(targetJavaHome, "bin")
     45    def executable = new File(javaExecutablesPath, execName)
     46    if (!executable.exists()) {
     47        throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
     48    }
     49    executable.toString()
    4150}
    4251
     
    99108        }
    100109    }
     110
     111    // Set up Java override if configured (used to test with Java 7).
     112    def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
     113    if (targetJavaHome) {
     114        if (JavaVersion.current().java9Compatible) {
     115            throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
     116        }
     117
     118        project.afterEvaluate {
     119            logger.info("Target Java home set to ${targetJavaHome}")
     120            logger.info("Configuring Gradle to use forked compilation and testing")
     121
     122            tasks.withType(JavaCompile) {
     123                options.fork = true
     124                options.forkOptions.javaHome = file(targetJavaHome)
     125            }
     126
     127            tasks.withType(Javadoc) {
     128                executable = javaExecutable(targetJavaHome, "javadoc")
     129            }
     130
     131            tasks.withType(Test) {
     132                executable = javaExecutable(targetJavaHome, "java")
     133            }
     134
     135            tasks.withType(JavaExec) {
     136                executable = javaExecutable(targetJavaHome, "java")
     137            }
     138        }
     139    }
    101140}
    102141
Note: See TracChangeset for help on using the changeset viewer.