Last active
May 8, 2019 18:10
-
-
Save jb08/8f3fe5d93bd49a0f24d312eb87df772e to your computer and use it in GitHub Desktop.
gradle cross-compile to an older Java version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If on JDK 9+, verify project cross-compiles on its 'sourceCompatible' JVM version (see https://github.com/melix/mrjar-gradle/blob/master/jdks.gradle) | |
if (project.hasProperty('crossCompile')) { | |
if (JavaVersion.current().java9Compatible) { | |
project.afterEvaluate { | |
tasks.withType(JavaCompile) { | |
def version = compat(sourceCompatibility) | |
project.logger.info("Configuring $name to use --release $version") | |
options.compilerArgs.addAll(['--release', version]) | |
} | |
} | |
} else { | |
project.logger.warn("-PcrossCompile not supported prior to JDK 9; using JDK ${JavaVersion.current()}") | |
} | |
} | |
// This function converts 1.8 -> 8 | |
static String compat(String src) { | |
if (src.contains('.')) { | |
src.substring(src.lastIndexOf('.')+1) | |
} else { | |
src | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment