Changeset 9731c20 for build.gradle


Ignore:
Timestamp:
Feb 17, 2019 2:13:32 AM (14 months ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
2556c77
Parents:
a1b67e3
Message:

Gradle: Improve cross-compilation support

JDK 9+ have a —release flag that correctly configures the bootClasspath.
For JDK 8 we now enforce manual configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • build.gradle

    ra1b67e3 r9731c20  
    3333}
    3434
     35String compat(String src) {
     36    if (src.contains('.')) {
     37        src.substring(src.lastIndexOf('.') + 1)
     38    } else {
     39        src
     40    }
     41}
     42
    3543def releaseVersion = getReleaseVersion()
    3644def buildVersion = getBuildVersion()
     
    6472
    6573    sourceCompatibility = 1.7
    66     // Set i2pBootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
     74    targetCompatibility = 1.7
     75
     76    def i2pBootClasspath
     77    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
     78    if (java7BootClasspath) {
     79        i2pBootClasspath = java7BootClasspath
     80    } else {
     81        def java7Home = System.getenv("JAVA7_HOME")
     82        if (java7Home) {
     83            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
     84        }
     85    }
     86
    6787    if (i2pBootClasspath) {
    6888        tasks.withType(AbstractCompile, { AbstractCompile ac ->
    6989            ac.options.bootstrapClasspath = files(i2pBootClasspath)
    7090        })
     91    } else {
     92        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
     93            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
     94        }
     95        tasks.withType(JavaCompile) {
     96            def version = compat(sourceCompatibility)
     97            logger.info("Configuring $name to use --release $version")
     98            options.compilerArgs.addAll(['--release', version])
     99        }
    71100    }
    72101}
Note: See TracChangeset for help on using the changeset viewer.