Skip to content

Commit ecdbd37

Browse files
authored
Refactor global build info plugin to leverage JavaInstallationRegistry (#53994)
This commit removes the configuration time vs execution time distinction with regards to certain BuildParms properties. Because of the cost of determining Java versions for configuration JDK locations we deferred this until execution time. This had two main downsides. First, we had to implement all this build logic in tasks, which required a bunch of additional plumbing and complexity. Second, because some information wasn't known during configuration time, we had to nest any build logic that depended on this in awkward callbacks. We now defer to the JavaInstallationRegistry recently added in Gradle. This utility uses a much more efficient method for probing Java installations vs our jrunscript implementation. This, combined with some optimizations to avoid probing the current JVM as well as deferring some evaluation via Providers when probing installations for BWC builds we can maintain effectively the same configuration time performance while removing a bunch of complexity and runtime cost (snapshotting inputs for the GenerateGlobalBuildInfoTask was very expensive). The end result should be a much more responsive build execution in almost all scenarios.
1 parent 586f4b7 commit ecdbd37

25 files changed

+220
-566
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ be used to test against other JDKs as well, this is not only limited to JDK 11.
103103
> Note: It is also required to have `JAVA8_HOME`, `JAVA9_HOME`, `JAVA10_HOME`
104104
and `JAVA11_HOME`, and `JAVA12_HOME` available so that the tests can pass.
105105

106-
> Warning: do not use `sdkman` for Java installations which do not have proper
107-
`jrunscript` for jdk distributions.
108-
109106
Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle
110107
using the wrapper via the `gradlew` script on Unix systems or `gradlew.bat`
111108
script on Windows in the root of the repository. The examples below show the

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder
3131
import org.gradle.util.DistributionLocator
3232
import org.gradle.util.GradleVersion
3333

34-
import static org.elasticsearch.gradle.tool.Boilerplate.maybeConfigure
34+
import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
3535

3636
plugins {
3737
id 'lifecycle-base'

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
3232
import org.elasticsearch.gradle.test.ErrorReportingTestListener
3333
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
3434
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
35-
import org.elasticsearch.gradle.tool.Boilerplate
35+
import org.elasticsearch.gradle.util.GradleUtils
3636
import org.gradle.api.Action
3737
import org.gradle.api.GradleException
3838
import org.gradle.api.InvalidUserDataException
@@ -82,7 +82,7 @@ import org.gradle.util.GradleVersion
8282
import java.nio.charset.StandardCharsets
8383
import java.nio.file.Files
8484

85-
import static org.elasticsearch.gradle.tool.Boilerplate.maybeConfigure
85+
import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
8686

8787
/**
8888
* Encapsulates build configuration for elasticsearch projects.
@@ -148,7 +148,7 @@ class BuildPlugin implements Plugin<Project> {
148148
File securityPolicy = buildResources.copy("fips_java.policy")
149149
File bcfksKeystore = buildResources.copy("cacerts.bcfks")
150150
// This configuration can be removed once system modules are available
151-
Boilerplate.maybeCreate(project.configurations, 'extraJars') {
151+
GradleUtils.maybeCreate(project.configurations, 'extraJars') {
152152
project.dependencies.add('extraJars', "org.bouncycastle:bc-fips:1.0.1")
153153
project.dependencies.add('extraJars', "org.bouncycastle:bctls-fips:1.0.9")
154154
}
@@ -235,7 +235,7 @@ class BuildPlugin implements Plugin<Project> {
235235
static String getJavaHome(final Task task, final int version) {
236236
requireJavaHome(task, version)
237237
JavaHome java = BuildParams.javaVersions.find { it.version == version }
238-
return java == null ? null : java.javaHome.absolutePath
238+
return java == null ? null : java.javaHome.get().absolutePath
239239
}
240240

241241
/**

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,13 @@ class PrecommitTasks {
143143
ExportElasticsearchBuildResourcesTask buildResources = project.tasks.getByName('buildResources')
144144
project.tasks.withType(CheckForbiddenApis).configureEach {
145145
dependsOn(buildResources)
146-
doFirst {
147-
// we need to defer this configuration since we don't know the runtime java version until execution time
148-
targetCompatibility = BuildParams.runtimeJavaVersion.majorVersion
149-
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_13) {
150-
project.logger.warn(
151-
"Forbidden APIs does not support Java versions past 13. Will use the signatures from 13 for {}.",
152-
BuildParams.runtimeJavaVersion
153-
)
154-
targetCompatibility = JavaVersion.VERSION_13.majorVersion
155-
}
146+
targetCompatibility = BuildParams.runtimeJavaVersion.majorVersion
147+
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_13) {
148+
project.logger.warn(
149+
"Forbidden APIs does not support Java versions past 13. Will use the signatures from 13 for {}.",
150+
BuildParams.runtimeJavaVersion
151+
)
152+
targetCompatibility = JavaVersion.VERSION_13.majorVersion
156153
}
157154
bundledSignatures = [
158155
"jdk-unsafe", "jdk-deprecated", "jdk-non-portable", "jdk-system-out"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.elasticsearch.gradle.docker.DockerSupportService;
2727
import org.elasticsearch.gradle.info.BuildParams;
2828
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin;
29-
import org.elasticsearch.gradle.tool.Boilerplate;
29+
import org.elasticsearch.gradle.util.GradleUtils;
3030
import org.gradle.api.GradleException;
3131
import org.gradle.api.NamedDomainObjectContainer;
3232
import org.gradle.api.Plugin;
@@ -52,7 +52,7 @@
5252
import java.util.concurrent.Callable;
5353
import java.util.function.Supplier;
5454

55-
import static org.elasticsearch.gradle.Util.capitalize;
55+
import static org.elasticsearch.gradle.util.Util.capitalize;
5656

5757
/**
5858
* A plugin to manage getting and extracting distributions of Elasticsearch.
@@ -77,7 +77,7 @@ public void apply(Project project) {
7777
project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
7878
project.getRootProject().getPluginManager().apply(DockerSupportPlugin.class);
7979

80-
Provider<DockerSupportService> dockerSupport = Boilerplate.getBuildService(
80+
Provider<DockerSupportService> dockerSupport = GradleUtils.getBuildService(
8181
project.getGradle().getSharedServices(),
8282
DockerSupportPlugin.DOCKER_SUPPORT_SERVICE_NAME
8383
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
import java.util.concurrent.Callable;
4848
import java.util.stream.StreamSupport;
4949

50-
import static org.elasticsearch.gradle.tool.Boilerplate.findByName;
51-
import static org.elasticsearch.gradle.tool.Boilerplate.maybeCreate;
50+
import static org.elasticsearch.gradle.util.GradleUtils.findByName;
51+
import static org.elasticsearch.gradle.util.GradleUtils.maybeCreate;
5252

5353
public class JdkDownloadPlugin implements Plugin<Project> {
5454

0 commit comments

Comments
 (0)