From de7bed2ab28d0804dcfa1879a75f65c96f7bd4f7 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 12 Feb 2020 14:30:29 +0100 Subject: [PATCH] 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 --- gradle/custom-java-home.gradle | 35 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/gradle/custom-java-home.gradle b/gradle/custom-java-home.gradle index a9a41ae9c7f..eca268e65f2 100644 --- a/gradle/custom-java-home.gradle +++ b/gradle/custom-java-home.gradle @@ -34,53 +34,42 @@ import org.gradle.internal.os.OperatingSystem def customJavaHome = System.getProperty("customJavaHome") if (customJavaHome) { - def javacExecutable = customJavaHome + "/bin/javac" - def javaExecutable = customJavaHome + "/bin/java" - if (OperatingSystem.current().isWindows()) { - javacExecutable += ".exe" - javaExecutable += ".exe" - } - + def customJavaHomeDir = new File(customJavaHome) def customJavaSourceVersion = System.getProperty("customJavaSourceVersion") tasks.withType(JavaCompile) { - logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable) - doFirst { - // Avoid compiler warnings for non-existing path entries - 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" + logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHomeDir) + options.forkOptions.javaHome = customJavaHomeDir + inputs.property("customJavaHome", customJavaHome) if (customJavaSourceVersion) { options.compilerArgs += [ "--release", customJavaSourceVersion] inputs.property("customJavaSourceVersion", customJavaSourceVersion) } - inputs.property("customJavaHome", customJavaHome) } tasks.withType(GroovyCompile) { - logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable) - options.fork = true - options.forkOptions.executable = javacExecutable + logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHomeDir) + options.forkOptions.executable = customJavaHomeDir + inputs.property("customJavaHome", customJavaHome) if (customJavaSourceVersion) { options.compilerArgs += [ "--release", customJavaSourceVersion] inputs.property("customJavaSourceVersion", customJavaSourceVersion) } - inputs.property("customJavaHome", customJavaHome) } /* tasks.withType(KotlinJvmCompile) { logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHome) - kotlinOptions.jdkHome = customJavaHome + kotlinOptions.jdkHome = customJavaHomeDir inputs.property("customJavaHome", customJavaHome) } */ 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) executable = javaExecutable inputs.property("customJavaHome", customJavaHome)