Remove compiler java version flag (#57237)

This commit removes the compiler.java setting from the build. It was
originally added when Gradle was far behind support for the latest jdk,
but is no longer applicable as we don't have any need to update the
supported compile version before gradle supports the newer version. Note
that the runtime version changing support still exists here, this only
ensures we use the same jdk to compile as we use to run gradle.
This commit is contained in:
Ryan Ernst 2020-05-27 15:20:41 -07:00 committed by Ryan Ernst
parent 3ead0a183b
commit beb1d0c338
No known key found for this signature in database
GPG Key ID: 5F7EA39E15F54DCE
5 changed files with 11 additions and 76 deletions

View File

@ -52,16 +52,12 @@ import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
import org.gradle.external.javadoc.CoreJavadocOptions;
import org.gradle.internal.jvm.Jvm;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@ -230,24 +226,10 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
throw new GradleException("Failed to get canonical path for " + file, e);
}
};
// common options to both java and groovy
Consumer<CompileOptions> configureFork = compileOptions -> {
// we only fork if the Gradle JDK is not the same as the compiler JDK
String compilerJavaHome = canonicalPath.apply(BuildParams.getCompilerJavaHome());
String currentJavaHome = canonicalPath.apply(Jvm.current().getJavaHome());
if (compilerJavaHome.equals(currentJavaHome)) {
compileOptions.setFork(false);
} else {
compileOptions.setFork(true);
compileOptions.getForkOptions().setJavaHome(BuildParams.getCompilerJavaHome());
}
};
project.afterEvaluate(p -> {
project.getTasks().withType(JavaCompile.class).configureEach(compileTask -> {
CompileOptions compileOptions = compileTask.getOptions();
configureFork.accept(compileOptions);
/*
* -path because gradle will send in paths that don't always exist.
* -missing because we have tons of missing @returns and @param.
@ -278,7 +260,6 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
});
// also apply release flag to groovy, which is used in build-tools
project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> {
configureFork.accept(compileTask.getOptions());
// TODO: this probably shouldn't apply to groovy at all?
// TODO: use native Gradle support for --release when available (cf. https://github.com/gradle/gradle/issues/2510)
@ -420,7 +401,6 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
// we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD
nonInputProperties.systemProperty("java.io.tmpdir", test.getWorkingDir().toPath().resolve("temp"));
nonInputProperties.systemProperty("compiler.java", BuildParams.getCompilerJavaVersion().getMajorVersion());
nonInputProperties.systemProperty("runtime.java", BuildParams.getRuntimeJavaVersion().getMajorVersion());
// TODO: remove setting logging level via system property
@ -497,7 +477,7 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
"Build-Date",
BuildParams.getBuildDate(),
"Build-Java-Version",
BuildParams.getCompilerJavaVersion()
BuildParams.getGradleJavaVersion()
)
);
}
@ -548,21 +528,11 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
private static void configureJavadoc(Project project) {
project.getTasks().withType(Javadoc.class).configureEach(javadoc -> {
// only explicitly set javadoc executable if compiler JDK is different from Gradle
// this ensures better cacheability as setting ths input to an absolute path breaks portability
Path compilerJvm = BuildParams.getCompilerJavaHome().toPath();
Path gradleJvm = Jvm.current().getJavaHome().toPath();
try {
if (Files.isSameFile(compilerJvm, gradleJvm) == false) {
javadoc.setExecutable(compilerJvm.resolve("bin/javadoc").toString());
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
// remove compiled classes from the Javadoc classpath:
// http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html
javadoc.setClasspath(Util.getJavaMainSourceSet(project).get().getCompileClasspath());
/*
* Generate docs using html5 to suppress a warning from `javadoc`
* that the default will change to html5 in the future.

View File

@ -70,8 +70,7 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
JavaVersion minimumCompilerVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumCompilerVersion"));
JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumRuntimeVersion"));
File compilerJavaHome = findCompilerJavaHome();
File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome);
File runtimeJavaHome = findRuntimeJavaHome();
File rootDir = project.getRootDir();
GitInfo gitInfo = gitInfo(rootDir);
@ -81,11 +80,9 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null;
params.reset();
params.setCompilerJavaHome(compilerJavaHome);
params.setRuntimeJavaHome(runtimeJavaHome);
params.setCompilerJavaVersion(determineJavaVersion("compiler java.home", compilerJavaHome, minimumCompilerVersion));
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion));
params.setIsRutimeJavaHomeSet(compilerJavaHome.equals(runtimeJavaHome) == false);
params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false);
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion));
params.setMinimumCompilerVersion(minimumCompilerVersion);
params.setMinimumRuntimeVersion(minimumRuntimeVersion);
@ -132,12 +129,8 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
LOGGER.quiet("Elasticsearch Build Hamster says Hello!");
LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion());
LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")");
if (Jvm.current().getJavaVersion().equals(BuildParams.getCompilerJavaVersion()) == false || BuildParams.getIsRuntimeJavaHomeSet()) {
String compilerJvmDetails = getJavaInstallation(BuildParams.getCompilerJavaHome()).getImplementationName();
if (BuildParams.getIsRuntimeJavaHomeSet()) {
String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName();
LOGGER.quiet(" Compiler JDK Version : " + BuildParams.getCompilerJavaVersion() + " (" + compilerJvmDetails + ")");
LOGGER.quiet(" Compiler java.home : " + BuildParams.getCompilerJavaHome());
LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")");
LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome());
LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")");
@ -233,26 +226,14 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
throw new GradleException(message);
}
private static File findCompilerJavaHome() {
String compilerJavaHome = System.getenv("JAVA_HOME");
String compilerJavaProperty = System.getProperty("compiler.java");
if (compilerJavaProperty != null) {
compilerJavaHome = findJavaHome(compilerJavaProperty);
}
// if JAVA_HOME is not set,so we use the JDK that Gradle was run with.
return compilerJavaHome == null ? Jvm.current().getJavaHome() : new File(compilerJavaHome);
}
private static File findRuntimeJavaHome(final File compilerJavaHome) {
private static File findRuntimeJavaHome() {
String runtimeJavaProperty = System.getProperty("runtime.java");
if (runtimeJavaProperty != null) {
return new File(findJavaHome(runtimeJavaProperty));
}
return System.getenv("RUNTIME_JAVA_HOME") == null ? compilerJavaHome : new File(System.getenv("RUNTIME_JAVA_HOME"));
return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME"));
}
private static String findJavaHome(String version) {

View File

@ -13,14 +13,12 @@ import java.util.function.Consumer;
import static java.util.Objects.requireNonNull;
public class BuildParams {
private static File compilerJavaHome;
private static File runtimeJavaHome;
private static Boolean isRuntimeJavaHomeSet;
private static List<JavaHome> javaVersions;
private static JavaVersion minimumCompilerVersion;
private static JavaVersion minimumRuntimeVersion;
private static JavaVersion gradleJavaVersion;
private static JavaVersion compilerJavaVersion;
private static JavaVersion runtimeJavaVersion;
private static Boolean inFipsJvm;
private static String gitRevision;
@ -45,10 +43,6 @@ public class BuildParams {
initializer.accept(MutableBuildParams.INSTANCE);
}
public static File getCompilerJavaHome() {
return value(compilerJavaHome);
}
public static File getRuntimeJavaHome() {
return value(runtimeJavaHome);
}
@ -73,10 +67,6 @@ public class BuildParams {
return value(gradleJavaVersion);
}
public static JavaVersion getCompilerJavaVersion() {
return value(compilerJavaVersion);
}
public static JavaVersion getRuntimeJavaVersion() {
return value(runtimeJavaVersion);
}
@ -162,10 +152,6 @@ public class BuildParams {
});
}
public void setCompilerJavaHome(File compilerJavaHome) {
BuildParams.compilerJavaHome = requireNonNull(compilerJavaHome);
}
public void setRuntimeJavaHome(File runtimeJavaHome) {
BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome);
}
@ -190,10 +176,6 @@ public class BuildParams {
BuildParams.gradleJavaVersion = requireNonNull(gradleJavaVersion);
}
public void setCompilerJavaVersion(JavaVersion compilerJavaVersion) {
BuildParams.compilerJavaVersion = requireNonNull(compilerJavaVersion);
}
public void setRuntimeJavaVersion(JavaVersion runtimeJavaVersion) {
BuildParams.runtimeJavaVersion = requireNonNull(runtimeJavaVersion);
}

View File

@ -1,5 +1,6 @@
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.info.BuildParams
import org.gradle.internal.jvm.Jvm
// Tell the tests we're running with ssl enabled
integTest.runner {
@ -26,7 +27,7 @@ task createNodeKeyStore(type: LoggedExec) {
delete nodeKeystore
}
}
executable = "${BuildParams.compilerJavaHome}/bin/keytool"
executable = "${Jvm.current().javaHome}/bin/keytool"
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
args '-genkey',
'-alias', 'test-node',

View File

@ -1,5 +1,6 @@
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.info.BuildParams
import org.gradle.internal.jvm.Jvm
// Tell the tests we're running with ssl enabled
integTest.runner {
@ -23,7 +24,7 @@ task createNodeKeyStore(type: LoggedExec) {
delete nodeKeystore
}
}
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
executable = "${Jvm.current().javaHome}/bin/keytool"
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
args '-genkey',
'-alias', 'test-node',