Simplify custom_java_home.gradle script
Setting `options.fork = true` causes the classpath in the forked compiler process to include Class-Path entries from MANIFEST.MF files in JARs in the classpath, which results in warnings about missing classpath entries. This commit removes the `options.fork = true` declaration and further simplifies the script. See gh-24474
This commit is contained in:
parent
9dbd411f81
commit
de7bed2ab2
|
@ -34,53 +34,42 @@ import org.gradle.internal.os.OperatingSystem
|
||||||
def customJavaHome = System.getProperty("customJavaHome")
|
def customJavaHome = System.getProperty("customJavaHome")
|
||||||
|
|
||||||
if (customJavaHome) {
|
if (customJavaHome) {
|
||||||
def javacExecutable = customJavaHome + "/bin/javac"
|
def customJavaHomeDir = new File(customJavaHome)
|
||||||
def javaExecutable = customJavaHome + "/bin/java"
|
|
||||||
if (OperatingSystem.current().isWindows()) {
|
|
||||||
javacExecutable += ".exe"
|
|
||||||
javaExecutable += ".exe"
|
|
||||||
}
|
|
||||||
|
|
||||||
def customJavaSourceVersion = System.getProperty("customJavaSourceVersion")
|
def customJavaSourceVersion = System.getProperty("customJavaSourceVersion")
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable)
|
logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHomeDir)
|
||||||
doFirst {
|
options.forkOptions.javaHome = customJavaHomeDir
|
||||||
// Avoid compiler warnings for non-existing path entries
|
inputs.property("customJavaHome", customJavaHome)
|
||||||
classpath = classpath.filter { it.exists() }
|
|
||||||
}
|
|
||||||
options.fork = true
|
|
||||||
options.forkOptions.executable = javacExecutable
|
|
||||||
// Ignore warnings about missing classpath elements -- for example, those picked up
|
|
||||||
// via Class-Path entries in MANIFEST.MF files in artifacts like xalan-2.7.2.jar.
|
|
||||||
options.compilerArgs -= "-Xlint:path"
|
|
||||||
if (customJavaSourceVersion) {
|
if (customJavaSourceVersion) {
|
||||||
options.compilerArgs += [ "--release", customJavaSourceVersion]
|
options.compilerArgs += [ "--release", customJavaSourceVersion]
|
||||||
inputs.property("customJavaSourceVersion", customJavaSourceVersion)
|
inputs.property("customJavaSourceVersion", customJavaSourceVersion)
|
||||||
}
|
}
|
||||||
inputs.property("customJavaHome", customJavaHome)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(GroovyCompile) {
|
tasks.withType(GroovyCompile) {
|
||||||
logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable)
|
logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHomeDir)
|
||||||
options.fork = true
|
options.forkOptions.executable = customJavaHomeDir
|
||||||
options.forkOptions.executable = javacExecutable
|
inputs.property("customJavaHome", customJavaHome)
|
||||||
if (customJavaSourceVersion) {
|
if (customJavaSourceVersion) {
|
||||||
options.compilerArgs += [ "--release", customJavaSourceVersion]
|
options.compilerArgs += [ "--release", customJavaSourceVersion]
|
||||||
inputs.property("customJavaSourceVersion", customJavaSourceVersion)
|
inputs.property("customJavaSourceVersion", customJavaSourceVersion)
|
||||||
}
|
}
|
||||||
inputs.property("customJavaHome", customJavaHome)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
tasks.withType(KotlinJvmCompile) {
|
tasks.withType(KotlinJvmCompile) {
|
||||||
logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHome)
|
logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHome)
|
||||||
kotlinOptions.jdkHome = customJavaHome
|
kotlinOptions.jdkHome = customJavaHomeDir
|
||||||
inputs.property("customJavaHome", customJavaHome)
|
inputs.property("customJavaHome", customJavaHome)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tasks.withType(Test) {
|
tasks.withType(Test) {
|
||||||
|
def javaExecutable = customJavaHome + "/bin/java"
|
||||||
|
if (OperatingSystem.current().isWindows()) {
|
||||||
|
javaExecutable += ".exe"
|
||||||
|
}
|
||||||
logger.info("Java executable for " + it.name + " task in " + project.name + ": " + javaExecutable)
|
logger.info("Java executable for " + it.name + " task in " + project.name + ": " + javaExecutable)
|
||||||
executable = javaExecutable
|
executable = javaExecutable
|
||||||
inputs.property("customJavaHome", customJavaHome)
|
inputs.property("customJavaHome", customJavaHome)
|
||||||
|
|
Loading…
Reference in New Issue