Browse Source

Reapply "[Build] Do not invalidate configuration cache when branch is switched (#118894)" (#119300) (#119325) (#119351)

* Reapply "[Build] Do not invalidate configuration cache when branch is switched (#118894)" (#119300)

The original PR (#118894) has broken serverless.

* Fix gitinfo plugin for serverless usage

* Update buildscan git revision reference

(cherry picked from commit 5278159987c90ed3001e0c6092d5d0c122f8e432)
Rene Groeschke 9 tháng trước cách đây
mục cha
commit
2b0592ddf6
19 tập tin đã thay đổi với 136 bổ sung76 xóa
  1. 16 18
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/GitInfoPlugin.java
  2. 23 13
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/LicensingPlugin.java
  3. 4 3
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java
  4. 12 0
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java
  5. 22 0
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfoValueSource.java
  6. 11 2
      build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java
  7. 20 14
      build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy
  8. 5 4
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java
  9. 2 2
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BuildParameterExtension.java
  10. 7 7
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/DefaultBuildParameterExtension.java
  11. 5 4
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java
  12. 2 2
      build-tools-internal/src/test/groovy/org/elasticsearch/gradle/internal/info/BuildParameterExtensionSpec.groovy
  13. 1 1
      client/rest/build.gradle
  14. 1 1
      client/sniffer/build.gradle
  15. 1 1
      client/test/build.gradle
  16. 1 1
      libs/h3/build.gradle
  17. 1 1
      libs/tdigest/build.gradle
  18. 1 1
      rest-api-spec/build.gradle
  19. 1 1
      x-pack/build.gradle

+ 16 - 18
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/GitInfoPlugin.java

@@ -10,47 +10,45 @@
 package org.elasticsearch.gradle.internal.conventions;
 
 import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
+import org.elasticsearch.gradle.internal.conventions.info.GitInfoValueSource;
 import org.elasticsearch.gradle.internal.conventions.util.Util;
 import org.gradle.api.Plugin;
 import org.gradle.api.Project;
-import org.gradle.api.model.ObjectFactory;
 import org.gradle.api.provider.Property;
 import org.gradle.api.provider.Provider;
 import org.gradle.api.provider.ProviderFactory;
 
-import javax.inject.Inject;
 import java.io.File;
 
-class GitInfoPlugin implements Plugin<Project> {
+import javax.inject.Inject;
 
-    private ProviderFactory factory;
-    private ObjectFactory objectFactory;
+public abstract class GitInfoPlugin implements Plugin<Project> {
 
+    private ProviderFactory factory;
     private Provider<String> revision;
-    private Property<GitInfo> gitInfo;
 
     @Inject
-    GitInfoPlugin(ProviderFactory factory, ObjectFactory objectFactory) {
+    public GitInfoPlugin(ProviderFactory factory) {
         this.factory = factory;
-        this.objectFactory = objectFactory;
     }
 
     @Override
     public void apply(Project project) {
-        File rootDir = Util.locateElasticsearchWorkspace(project.getGradle());
-        gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
-            GitInfo.gitInfo(rootDir)
-        ));
-        gitInfo.disallowChanges();
-        gitInfo.finalizeValueOnRead();
-
-        revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "main");
+        File rootDir = getGitRootDir(project);
+        getGitInfo().convention(factory.of(GitInfoValueSource.class, spec -> { spec.getParameters().getPath().set(rootDir); }));
+        revision = getGitInfo().map(info -> info.getRevision() == null ? info.getRevision() : "main");
     }
 
-    public Property<GitInfo> getGitInfo() {
-        return gitInfo;
+    private static File getGitRootDir(Project project) {
+        File rootDir = project.getRootDir();
+        if (new File(rootDir, ".git").exists()) {
+            return rootDir;
+        }
+        return Util.locateElasticsearchWorkspace(project.getGradle());
     }
 
+    public abstract Property<GitInfo> getGitInfo();
+
     public Provider<String> getRevision() {
         return revision;
     }

+ 23 - 13
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/LicensingPlugin.java

@@ -15,9 +15,10 @@ import org.gradle.api.provider.MapProperty;
 import org.gradle.api.provider.Provider;
 import org.gradle.api.provider.ProviderFactory;
 
-import javax.inject.Inject;
 import java.util.Map;
 
+import javax.inject.Inject;
+
 public class LicensingPlugin implements Plugin<Project> {
     static final String ELASTIC_LICENSE_URL_PREFIX = "https://raw.githubusercontent.com/elastic/elasticsearch/";
     static final String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";
@@ -33,24 +34,33 @@ public class LicensingPlugin implements Plugin<Project> {
     @Override
     public void apply(Project project) {
         Provider<String> revision = project.getRootProject().getPlugins().apply(GitInfoPlugin.class).getRevision();
-        Provider<String> licenseCommitProvider = providerFactory.provider(() ->
-             isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
+        Provider<String> licenseCommitProvider = providerFactory.provider(
+            () -> isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
         );
 
-        Provider<String> elasticLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
-                licenseCommit + ELASTIC_LICENSE_URL_POSTFIX);
-        Provider<String> agplLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
-            licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX);
+        Provider<String> elasticLicenseURL = licenseCommitProvider.map(
+            licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + ELASTIC_LICENSE_URL_POSTFIX
+        );
+        Provider<String> agplLicenseURL = licenseCommitProvider.map(
+            licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX
+        );
         // But stick the Elastic license url in project.ext so we can get it if we need to switch to it
         project.getExtensions().getExtraProperties().set("elasticLicenseUrl", elasticLicenseURL);
 
-        MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class).convention(
-                providerFactory.provider(() -> Map.of(
-                        "Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
-                        "Elastic License 2.0", elasticLicenseURL.get(),
-                        "GNU Affero General Public License Version 3", agplLicenseURL.get())
+        MapProperty<String, Provider<String>> licensesProperty = project.getObjects()
+            .mapProperty(String.class, (Class<Provider<String>>) (Class<?>) Provider.class)
+            .convention(
+                providerFactory.provider(
+                    () -> Map.of(
+                        "Server Side Public License, v 1",
+                        providerFactory.provider(() -> "https://www.mongodb.com/licensing/server-side-public-license"),
+                        "Elastic License 2.0",
+                        elasticLicenseURL,
+                        "GNU Affero General Public License Version 3",
+                        agplLicenseURL
+                    )
                 )
-        );
+            );
 
         // Default to the SSPL+Elastic dual license
         project.getExtensions().getExtraProperties().set("projectLicenses", licensesProperty);

+ 4 - 3
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java

@@ -28,6 +28,7 @@ import org.gradle.api.plugins.ExtensionContainer;
 import org.gradle.api.plugins.JavaLibraryPlugin;
 import org.gradle.api.plugins.JavaPlugin;
 import org.gradle.api.provider.MapProperty;
+import org.gradle.api.provider.Provider;
 import org.gradle.api.provider.ProviderFactory;
 import org.gradle.api.publish.PublishingExtension;
 import org.gradle.api.publish.maven.MavenPublication;
@@ -42,6 +43,7 @@ import org.w3c.dom.Element;
 import java.io.File;
 import java.util.Map;
 import java.util.concurrent.Callable;
+
 import javax.inject.Inject;
 
 public class PublishPlugin implements Plugin<Project> {
@@ -81,7 +83,7 @@ public class PublishPlugin implements Plugin<Project> {
             }
         });
         @SuppressWarnings("unchecked")
-        var projectLicenses = (MapProperty<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
+        var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
         publication.getPom().withXml(xml -> {
             var node = xml.asNode();
             node.appendNode("inceptionYear", "2009");
@@ -89,7 +91,7 @@ public class PublishPlugin implements Plugin<Project> {
             projectLicenses.get().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
                 Node license = licensesNode.appendNode("license");
                 license.appendNode("name", entry.getKey());
-                license.appendNode("url", entry.getValue());
+                license.appendNode("url", entry.getValue().get());
                 license.appendNode("distribution", "repo");
             });
             var developer = node.appendNode("developers").appendNode("developer");
@@ -194,7 +196,6 @@ public class PublishPlugin implements Plugin<Project> {
         });
     }
 
-
     /**
      * Format the generated pom files to be in a sort of reproducible order.
      */

+ 12 - 0
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java

@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -190,4 +191,15 @@ public class GitInfo {
         }
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) return false;
+        GitInfo gitInfo = (GitInfo) o;
+        return Objects.equals(revision, gitInfo.revision) && Objects.equals(origin, gitInfo.origin);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(revision, origin);
+    }
 }

+ 22 - 0
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfoValueSource.java

@@ -0,0 +1,22 @@
+package org.elasticsearch.gradle.internal.conventions.info;
+
+import org.gradle.api.provider.Property;
+import org.gradle.api.provider.ValueSource;
+import org.gradle.api.provider.ValueSourceParameters;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+
+public abstract class GitInfoValueSource implements ValueSource<GitInfo, GitInfoValueSource.Parameters> {
+
+    @Nullable
+    @Override
+    public GitInfo obtain() {
+        File path = getParameters().getPath().get();
+        return GitInfo.gitInfo(path);
+    }
+
+    public interface Parameters extends ValueSourceParameters {
+        Property<File> getPath();
+    }
+}

+ 11 - 2
build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java

@@ -14,18 +14,19 @@ import org.gradle.api.GradleException;
 import org.gradle.api.Project;
 import org.gradle.api.file.FileTree;
 import org.gradle.api.initialization.IncludedBuild;
+import org.gradle.api.internal.GradleInternal;
 import org.gradle.api.invocation.Gradle;
 import org.gradle.api.plugins.JavaPluginExtension;
 import org.gradle.api.tasks.SourceSet;
 import org.gradle.api.tasks.SourceSetContainer;
 import org.gradle.api.tasks.util.PatternFilterable;
 
-import javax.annotation.Nullable;
 import java.io.File;
-import java.util.Collection;
 import java.util.Optional;
 import java.util.function.Supplier;
 
+import javax.annotation.Nullable;
+
 public class Util {
 
     public static boolean getBooleanProperty(String property, boolean defaultValue) {
@@ -120,6 +121,14 @@ public class Util {
         return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
     }
 
+    public static File getRootFolder(Gradle gradle) {
+        Gradle parent = gradle.getParent();
+        if (parent == null) {
+            return gradle.getRootProject().getRootDir();
+        }
+        return getRootFolder(parent);
+    }
+
     public static File locateElasticsearchWorkspace(Gradle gradle) {
         if (gradle.getRootProject().getName().startsWith("build-tools")) {
             File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile();

+ 20 - 14
build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy

@@ -45,7 +45,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         file("build/distributions/hello-world-1.0-javadoc.jar").exists()
         file("build/distributions/hello-world-1.0-sources.jar").exists()
         file("build/distributions/hello-world-1.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-1.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <!-- This module was also published with a richer model, Gradle metadata,  -->
   <!-- which should be used instead. Do not delete the following line which  -->
@@ -130,7 +131,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         file("build/distributions/hello-world-1.0-javadoc.jar").exists()
         file("build/distributions/hello-world-1.0-sources.jar").exists()
         file("build/distributions/hello-world-1.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-1.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <modelVersion>4.0.0</modelVersion>
               <groupId>org.acme</groupId>
@@ -219,7 +221,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         file("build/distributions/hello-world-1.0-javadoc.jar").exists()
         file("build/distributions/hello-world-1.0-sources.jar").exists()
         file("build/distributions/hello-world-1.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-1.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <modelVersion>4.0.0</modelVersion>
               <groupId>org.acme</groupId>
@@ -312,7 +315,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         file("build/distributions/hello-world-plugin-1.0-javadoc.jar").exists()
         file("build/distributions/hello-world-plugin-1.0-sources.jar").exists()
         file("build/distributions/hello-world-plugin-1.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-plugin-1.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-plugin-1.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <!-- This module was also published with a richer model, Gradle metadata,  -->
               <!-- which should be used instead. Do not delete the following line which  -->
@@ -389,7 +393,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         then:
         result.task(":generatePom").outcome == TaskOutcome.SUCCESS
         file("build/distributions/hello-world-plugin-2.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-plugin-2.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-plugin-2.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <!-- This module was also published with a richer model, Gradle metadata,  -->
               <!-- which should be used instead. Do not delete the following line which  -->
@@ -439,7 +444,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         // scm info only added for internal builds
         internalBuild()
         buildFile << """
-            buildParams.setGitOrigin("https://some-repo.com/repo.git")
+            buildParams.setGitOrigin(project.providers.provider(() -> "https://some-repo.com/repo.git"))
             apply plugin:'elasticsearch.java'
             apply plugin:'elasticsearch.publish'
 
@@ -447,7 +452,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
             group = 'org.acme'
             description = "just a test project"
 
-            ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+            ext.projectLicenses.set(['The Apache Software License, Version 2.0': project.providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
         """
 
         when:
@@ -456,7 +461,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
         then:
         result.task(":generatePom").outcome == TaskOutcome.SUCCESS
         file("build/distributions/hello-world-1.0.pom").exists()
-        assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
+        assertXmlEquals(
+            file("build/distributions/hello-world-1.0.pom").text, """
             <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <!-- This module was also published with a richer model, Gradle metadata,  -->
           <!-- which should be used instead. Do not delete the following line which  -->
@@ -493,15 +499,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
 
     private boolean assertXmlEquals(String toTest, String expected) {
         def diff = DiffBuilder.compare(Input.fromString(expected))
-                .ignoreWhitespace()
-                .ignoreComments()
-                .normalizeWhitespace()
-                .withTest(Input.fromString(toTest))
-                .build()
+            .ignoreWhitespace()
+            .ignoreComments()
+            .normalizeWhitespace()
+            .withTest(Input.fromString(toTest))
+            .build()
         diff.differences.each { difference ->
             println difference
         }
-        if(diff.differences.size() > 0) {
+        if (diff.differences.size() > 0) {
             println """ given:
 $toTest
 """

+ 5 - 4
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java

@@ -27,6 +27,7 @@ import org.gradle.api.plugins.BasePlugin;
 import org.gradle.api.plugins.JavaLibraryPlugin;
 import org.gradle.api.plugins.JavaPlugin;
 import org.gradle.api.provider.Property;
+import org.gradle.api.provider.Provider;
 import org.gradle.api.tasks.TaskProvider;
 import org.gradle.api.tasks.bundling.Jar;
 import org.gradle.api.tasks.javadoc.Javadoc;
@@ -108,12 +109,12 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
     }
 
     private static void configureJarManifest(Project project, BuildParameterExtension buildParams) {
-        String gitOrigin = buildParams.getGitOrigin();
-        String gitRevision = buildParams.getGitRevision();
+        Provider<String> gitOrigin = buildParams.getGitOrigin();
+        Provider<String> gitRevision = buildParams.getGitRevision();
 
         project.getPlugins().withType(InfoBrokerPlugin.class).whenPluginAdded(manifestPlugin -> {
-            manifestPlugin.add("Module-Origin", toStringable(() -> gitOrigin));
-            manifestPlugin.add("Change", toStringable(() -> gitRevision));
+            manifestPlugin.add("Module-Origin", toStringable(() -> gitOrigin.get()));
+            manifestPlugin.add("Change", toStringable(() -> gitRevision.get()));
             manifestPlugin.add("X-Compile-Elasticsearch-Version", toStringable(VersionProperties::getElasticsearch));
             manifestPlugin.add("X-Compile-Lucene-Version", toStringable(VersionProperties::getLucene));
             manifestPlugin.add(

+ 2 - 2
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BuildParameterExtension.java

@@ -46,9 +46,9 @@ public interface BuildParameterExtension {
 
     Provider<String> getRuntimeJavaDetails();
 
-    String getGitRevision();
+    Provider<String> getGitRevision();
 
-    String getGitOrigin();
+    Provider<String> getGitOrigin();
 
     ZonedDateTime getBuildDate();
 

+ 7 - 7
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/DefaultBuildParameterExtension.java

@@ -36,7 +36,7 @@ public abstract class DefaultBuildParameterExtension implements BuildParameterEx
     private final Provider<JavaVersion> runtimeJavaVersion;
     private final Provider<? extends Action<JavaToolchainSpec>> javaToolChainSpec;
     private final Provider<String> runtimeJavaDetails;
-    private final String gitRevision;
+    private final Provider<String> gitRevision;
 
     private transient AtomicReference<ZonedDateTime> buildDate = new AtomicReference<>();
     private final String testSeed;
@@ -46,7 +46,7 @@ public abstract class DefaultBuildParameterExtension implements BuildParameterEx
 
     // not final for testing
     private Provider<BwcVersions> bwcVersions;
-    private String gitOrigin;
+    private Provider<String> gitOrigin;
 
     public DefaultBuildParameterExtension(
         ProviderFactory providers,
@@ -59,8 +59,8 @@ public abstract class DefaultBuildParameterExtension implements BuildParameterEx
         JavaVersion minimumCompilerVersion,
         JavaVersion minimumRuntimeVersion,
         JavaVersion gradleJavaVersion,
-        String gitRevision,
-        String gitOrigin,
+        Provider<String> gitRevision,
+        Provider<String> gitOrigin,
         String testSeed,
         boolean isCi,
         int defaultParallel,
@@ -155,12 +155,12 @@ public abstract class DefaultBuildParameterExtension implements BuildParameterEx
     }
 
     @Override
-    public String getGitRevision() {
+    public Provider<String> getGitRevision() {
         return gitRevision;
     }
 
     @Override
-    public String getGitOrigin() {
+    public Provider<String> getGitOrigin() {
         return gitOrigin;
     }
 
@@ -239,7 +239,7 @@ public abstract class DefaultBuildParameterExtension implements BuildParameterEx
     }
 
     // for testing; not part of public api
-    public void setGitOrigin(String gitOrigin) {
+    public void setGitOrigin(Provider<String> gitOrigin) {
         this.gitOrigin = gitOrigin;
     }
 }

+ 5 - 4
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java

@@ -14,6 +14,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.io.IOUtils;
 import org.elasticsearch.gradle.VersionProperties;
 import org.elasticsearch.gradle.internal.BwcVersions;
+import org.elasticsearch.gradle.internal.conventions.GitInfoPlugin;
 import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
 import org.elasticsearch.gradle.internal.conventions.info.ParallelDetector;
 import org.elasticsearch.gradle.internal.conventions.util.Util;
@@ -96,6 +97,8 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
         }
         this.project = project;
         project.getPlugins().apply(JvmToolchainsPlugin.class);
+        Provider<GitInfo> gitInfo = project.getPlugins().apply(GitInfoPlugin.class).getGitInfo();
+
         toolChainService = project.getExtensions().getByType(JavaToolchainService.class);
         GradleVersion minimumGradleVersion = GradleVersion.version(getResourceContents("/minimumGradleVersion"));
         if (GradleVersion.current().compareTo(minimumGradleVersion) < 0) {
@@ -111,8 +114,6 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
             ? explicitRuntimeJavaHome
             : resolveJavaHomeFromToolChainService(VersionProperties.getBundledJdkMajorVersion());
 
-        GitInfo gitInfo = GitInfo.gitInfo(project.getRootDir());
-
         Provider<JvmInstallationMetadata> runtimeJdkMetaData = actualRuntimeJavaHome.map(
             runtimeJavaHome -> metadataDetector.getMetadata(getJavaInstallation(runtimeJavaHome))
         );
@@ -143,8 +144,8 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
                 minimumCompilerVersion,
                 minimumRuntimeVersion,
                 Jvm.current().getJavaVersion(),
-                gitInfo.getRevision(),
-                gitInfo.getOrigin(),
+                gitInfo.map(g -> g.getRevision()),
+                gitInfo.map(g -> g.getOrigin()),
                 getTestSeed(),
                 System.getenv("JENKINS_URL") != null || System.getenv("BUILDKITE_BUILD_URL") != null || System.getProperty("isCI") != null,
                 ParallelDetector.findDefaultParallel(project),

+ 2 - 2
build-tools-internal/src/test/groovy/org/elasticsearch/gradle/internal/info/BuildParameterExtensionSpec.groovy

@@ -86,8 +86,8 @@ class BuildParameterExtensionSpec extends Specification {
             JavaVersion.VERSION_11,
             JavaVersion.VERSION_11,
             JavaVersion.VERSION_11,
-            "gitRevision",
-            "gitOrigin",
+            providerMock(),
+            providerMock(),
             "testSeed",
             false,
             5,

+ 1 - 1
client/rest/build.gradle

@@ -36,7 +36,7 @@ base {
 }
 
 // LLRC is licenses under Apache 2.0
-projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 dependencies {

+ 1 - 1
client/sniffer/build.gradle

@@ -32,7 +32,7 @@ base {
 }
 
 // rest client sniffer is licenses under Apache 2.0
-projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 dependencies {

+ 1 - 1
client/test/build.gradle

@@ -18,7 +18,7 @@ java {
 group = "${group}.client.test"
 
 // rest client sniffer is licenses under Apache 2.0
-projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 dependencies {

+ 1 - 1
libs/h3/build.gradle

@@ -35,7 +35,7 @@ tasks.named('forbiddenApisMain').configure {
   replaceSignatureFiles 'jdk-signatures'
 }
 
-ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+ext.projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 tasks.withType(LicenseHeadersTask.class).configureEach {

+ 1 - 1
libs/tdigest/build.gradle

@@ -36,7 +36,7 @@ tasks.named('forbiddenApisMain').configure {
   replaceSignatureFiles 'jdk-signatures'
 }
 
-ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+ext.projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 tasks.withType(LicenseHeadersTask.class).configureEach {

+ 1 - 1
rest-api-spec/build.gradle

@@ -13,7 +13,7 @@ restResources {
 }
 
 // REST API specifications are published under the Apache 2.0 License
-ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
+ext.projectLicenses.set(['The Apache Software License, Version 2.0': providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
 licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt'))
 
 configurations {

+ 1 - 1
x-pack/build.gradle

@@ -36,7 +36,7 @@ subprojects {
   }
 
   project.pluginManager.withPlugin("elasticsearch.licensing") {
-    ext.projectLicenses.set(['Elastic License 2.0': ext.elasticLicenseUrl.get()])
+    ext.projectLicenses.set(['Elastic License 2.0': ext.elasticLicenseUrl])
   }
 
   project.pluginManager.withPlugin("elasticsearch.build") {