Skip to content

Commit 2d99858

Browse files
committed
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.
1 parent e1cb4dd commit 2d99858

File tree

6 files changed

+13
-77
lines changed

6 files changed

+13
-77
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@
5252
import org.gradle.api.tasks.javadoc.Javadoc;
5353
import org.gradle.api.tasks.testing.Test;
5454
import org.gradle.external.javadoc.CoreJavadocOptions;
55-
import org.gradle.internal.jvm.Jvm;
5655
import org.gradle.language.base.plugins.LifecycleBasePlugin;
5756

5857
import java.io.File;
5958
import java.io.IOException;
60-
import java.io.UncheckedIOException;
6159
import java.net.MalformedURLException;
6260
import java.net.URI;
63-
import java.nio.file.Files;
64-
import java.nio.file.Path;
6561
import java.util.Arrays;
6662
import java.util.List;
6763
import java.util.Locale;
@@ -230,24 +226,10 @@ public static void configureCompile(Project project) {
230226
throw new GradleException("Failed to get canonical path for " + file, e);
231227
}
232228
};
233-
// common options to both java and groovy
234-
Consumer<CompileOptions> configureFork = compileOptions -> {
235-
// we only fork if the Gradle JDK is not the same as the compiler JDK
236-
String compilerJavaHome = canonicalPath.apply(BuildParams.getCompilerJavaHome());
237-
String currentJavaHome = canonicalPath.apply(Jvm.current().getJavaHome());
238-
if (compilerJavaHome.equals(currentJavaHome)) {
239-
compileOptions.setFork(false);
240-
} else {
241-
compileOptions.setFork(true);
242-
compileOptions.getForkOptions().setJavaHome(BuildParams.getCompilerJavaHome());
243-
}
244-
};
245229

246230
project.afterEvaluate(p -> {
247231
project.getTasks().withType(JavaCompile.class).configureEach(compileTask -> {
248232
CompileOptions compileOptions = compileTask.getOptions();
249-
250-
configureFork.accept(compileOptions);
251233
/*
252234
* -path because gradle will send in paths that don't always exist.
253235
* -missing because we have tons of missing @returns and @param.
@@ -278,7 +260,6 @@ public static void configureCompile(Project project) {
278260
});
279261
// also apply release flag to groovy, which is used in build-tools
280262
project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> {
281-
configureFork.accept(compileTask.getOptions());
282263

283264
// TODO: this probably shouldn't apply to groovy at all?
284265
// TODO: use native Gradle support for --release when available (cf. https://github.com/gradle/gradle/issues/2510)
@@ -420,7 +401,6 @@ public void execute(Task t) {
420401
// we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD
421402
nonInputProperties.systemProperty("java.io.tmpdir", test.getWorkingDir().toPath().resolve("temp"));
422403

423-
nonInputProperties.systemProperty("compiler.java", BuildParams.getCompilerJavaVersion().getMajorVersion());
424404
nonInputProperties.systemProperty("runtime.java", BuildParams.getRuntimeJavaVersion().getMajorVersion());
425405

426406
// TODO: remove setting logging level via system property
@@ -497,7 +477,7 @@ static void configureJars(Project project) {
497477
"Build-Date",
498478
BuildParams.getBuildDate(),
499479
"Build-Java-Version",
500-
BuildParams.getCompilerJavaVersion()
480+
BuildParams.getGradleJavaVersion()
501481
)
502482
);
503483
}
@@ -548,21 +528,11 @@ private static void configureJarManifest(Project project) {
548528

549529
private static void configureJavadoc(Project project) {
550530
project.getTasks().withType(Javadoc.class).configureEach(javadoc -> {
551-
// only explicitly set javadoc executable if compiler JDK is different from Gradle
552-
// this ensures better cacheability as setting ths input to an absolute path breaks portability
553-
Path compilerJvm = BuildParams.getCompilerJavaHome().toPath();
554-
Path gradleJvm = Jvm.current().getJavaHome().toPath();
555-
try {
556-
if (Files.isSameFile(compilerJvm, gradleJvm) == false) {
557-
javadoc.setExecutable(compilerJvm.resolve("bin/javadoc").toString());
558-
}
559-
} catch (IOException e) {
560-
throw new UncheckedIOException(e);
561-
}
562531

563532
// remove compiled classes from the Javadoc classpath:
564533
// http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html
565534
javadoc.setClasspath(Util.getJavaMainSourceSet(project).get().getCompileClasspath());
535+
566536
/*
567537
* Generate docs using html5 to suppress a warning from `javadoc`
568538
* that the default will change to html5 in the future.

buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public void apply(Project project) {
7070
JavaVersion minimumCompilerVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumCompilerVersion"));
7171
JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumRuntimeVersion"));
7272

73-
File compilerJavaHome = findCompilerJavaHome();
74-
File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome);
73+
File runtimeJavaHome = findRuntimeJavaHome();
7574

7675
File rootDir = project.getRootDir();
7776
GitInfo gitInfo = gitInfo(rootDir);
@@ -81,11 +80,9 @@ public void apply(Project project) {
8180
boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null;
8281

8382
params.reset();
84-
params.setCompilerJavaHome(compilerJavaHome);
8583
params.setRuntimeJavaHome(runtimeJavaHome);
86-
params.setCompilerJavaVersion(determineJavaVersion("compiler java.home", compilerJavaHome, minimumCompilerVersion));
8784
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion));
88-
params.setIsRutimeJavaHomeSet(compilerJavaHome.equals(runtimeJavaHome) == false);
85+
params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false);
8986
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion));
9087
params.setMinimumCompilerVersion(minimumCompilerVersion);
9188
params.setMinimumRuntimeVersion(minimumRuntimeVersion);
@@ -132,12 +129,8 @@ private void logGlobalBuildInfo() {
132129
LOGGER.quiet("Elasticsearch Build Hamster says Hello!");
133130
LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion());
134131
LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")");
135-
if (Jvm.current().getJavaVersion().equals(BuildParams.getCompilerJavaVersion()) == false || BuildParams.getIsRuntimeJavaHomeSet()) {
136-
String compilerJvmDetails = getJavaInstallation(BuildParams.getCompilerJavaHome()).getImplementationName();
132+
if (BuildParams.getIsRuntimeJavaHomeSet()) {
137133
String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName();
138-
139-
LOGGER.quiet(" Compiler JDK Version : " + BuildParams.getCompilerJavaVersion() + " (" + compilerJvmDetails + ")");
140-
LOGGER.quiet(" Compiler java.home : " + BuildParams.getCompilerJavaHome());
141134
LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")");
142135
LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome());
143136
LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")");
@@ -233,26 +226,14 @@ private static void throwInvalidJavaHomeException(String description, File javaH
233226
throw new GradleException(message);
234227
}
235228

236-
private static File findCompilerJavaHome() {
237-
String compilerJavaHome = System.getenv("JAVA_HOME");
238-
String compilerJavaProperty = System.getProperty("compiler.java");
239-
240-
if (compilerJavaProperty != null) {
241-
compilerJavaHome = findJavaHome(compilerJavaProperty);
242-
}
243-
244-
// if JAVA_HOME is not set,so we use the JDK that Gradle was run with.
245-
return compilerJavaHome == null ? Jvm.current().getJavaHome() : new File(compilerJavaHome);
246-
}
247-
248-
private static File findRuntimeJavaHome(final File compilerJavaHome) {
229+
private static File findRuntimeJavaHome() {
249230
String runtimeJavaProperty = System.getProperty("runtime.java");
250231

251232
if (runtimeJavaProperty != null) {
252233
return new File(findJavaHome(runtimeJavaProperty));
253234
}
254235

255-
return System.getenv("RUNTIME_JAVA_HOME") == null ? compilerJavaHome : new File(System.getenv("RUNTIME_JAVA_HOME"));
236+
return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME"));
256237
}
257238

258239
private static String findJavaHome(String version) {

buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
import static java.util.Objects.requireNonNull;
1414

1515
public class BuildParams {
16-
private static File compilerJavaHome;
1716
private static File runtimeJavaHome;
1817
private static Boolean isRuntimeJavaHomeSet;
1918
private static List<JavaHome> javaVersions;
2019
private static JavaVersion minimumCompilerVersion;
2120
private static JavaVersion minimumRuntimeVersion;
2221
private static JavaVersion gradleJavaVersion;
23-
private static JavaVersion compilerJavaVersion;
2422
private static JavaVersion runtimeJavaVersion;
2523
private static Boolean inFipsJvm;
2624
private static String gitRevision;
@@ -45,10 +43,6 @@ public static void init(Consumer<MutableBuildParams> initializer) {
4543
initializer.accept(MutableBuildParams.INSTANCE);
4644
}
4745

48-
public static File getCompilerJavaHome() {
49-
return value(compilerJavaHome);
50-
}
51-
5246
public static File getRuntimeJavaHome() {
5347
return value(runtimeJavaHome);
5448
}
@@ -73,10 +67,6 @@ public static JavaVersion getGradleJavaVersion() {
7367
return value(gradleJavaVersion);
7468
}
7569

76-
public static JavaVersion getCompilerJavaVersion() {
77-
return value(compilerJavaVersion);
78-
}
79-
8070
public static JavaVersion getRuntimeJavaVersion() {
8171
return value(runtimeJavaVersion);
8272
}
@@ -162,10 +152,6 @@ public void reset() {
162152
});
163153
}
164154

165-
public void setCompilerJavaHome(File compilerJavaHome) {
166-
BuildParams.compilerJavaHome = requireNonNull(compilerJavaHome);
167-
}
168-
169155
public void setRuntimeJavaHome(File runtimeJavaHome) {
170156
BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome);
171157
}
@@ -190,10 +176,6 @@ public void setGradleJavaVersion(JavaVersion gradleJavaVersion) {
190176
BuildParams.gradleJavaVersion = requireNonNull(gradleJavaVersion);
191177
}
192178

193-
public void setCompilerJavaVersion(JavaVersion compilerJavaVersion) {
194-
BuildParams.compilerJavaVersion = requireNonNull(compilerJavaVersion);
195-
}
196-
197179
public void setRuntimeJavaVersion(JavaVersion runtimeJavaVersion) {
198180
BuildParams.runtimeJavaVersion = requireNonNull(runtimeJavaVersion);
199181
}

x-pack/plugin/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.elasticsearch.gradle.LoggedExec
22
import org.elasticsearch.gradle.info.BuildParams
33
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
4+
import org.gradle.internal.jvm.Jvm
45

56
import java.nio.charset.StandardCharsets
67

@@ -31,7 +32,7 @@ subprojects {
3132
dependsOn project.configurations.featureAwarePlugin
3233
outputs.file(successMarker)
3334

34-
executable = "${BuildParams.compilerJavaHome}/bin/java"
35+
executable = "${Jvm.current().javaHome}/bin/java"
3536

3637
// default to main class files if such a source set exists
3738
final List files = []

x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.elasticsearch.gradle.LoggedExec
22
import org.elasticsearch.gradle.info.BuildParams
3+
import org.gradle.internal.jvm.Jvm
34

45
// Tell the tests we're running with ssl enabled
56
integTest.runner {
@@ -26,7 +27,7 @@ task createNodeKeyStore(type: LoggedExec) {
2627
delete nodeKeystore
2728
}
2829
}
29-
executable = "${BuildParams.compilerJavaHome}/bin/keytool"
30+
executable = "${Jvm.current().javaHome}/bin/keytool"
3031
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
3132
args '-genkey',
3233
'-alias', 'test-node',

x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.elasticsearch.gradle.LoggedExec
22
import org.elasticsearch.gradle.info.BuildParams
3+
import org.gradle.internal.jvm.Jvm
34

45
// Tell the tests we're running with ssl enabled
56
integTest.runner {
@@ -23,7 +24,7 @@ task createNodeKeyStore(type: LoggedExec) {
2324
delete nodeKeystore
2425
}
2526
}
26-
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
27+
executable = "${Jvm.current().javaHome}/bin/keytool"
2728
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
2829
args '-genkey',
2930
'-alias', 'test-node',

0 commit comments

Comments
 (0)