From 3999f6eca2d982b5cfdcdc8196ccf396bc0be56d Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Fri, 13 Dec 2024 15:07:29 -0800 Subject: [PATCH] Improve efficiency of incremental builds when building bwc distributions --- .../InternalDistributionBwcSetupPlugin.java | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPlugin.java index da26cb66122ad..41d91574e8c02 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPlugin.java @@ -17,12 +17,12 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; +import org.gradle.api.file.FileSystemOperations; import org.gradle.api.file.ProjectLayout; import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.JvmToolchainsPlugin; import org.gradle.api.provider.Provider; import org.gradle.api.provider.ProviderFactory; -import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.PathSensitivity; import org.gradle.api.tasks.TaskProvider; import org.gradle.jvm.toolchain.JavaToolchainService; @@ -54,11 +54,17 @@ public class InternalDistributionBwcSetupPlugin implements Plugin { private final ObjectFactory objectFactory; private ProviderFactory providerFactory; private JavaToolchainService toolChainService; + private FileSystemOperations fileSystemOperations; @Inject - public InternalDistributionBwcSetupPlugin(ObjectFactory objectFactory, ProviderFactory providerFactory) { + public InternalDistributionBwcSetupPlugin( + ObjectFactory objectFactory, + ProviderFactory providerFactory, + FileSystemOperations fileSystemOperations + ) { this.objectFactory = objectFactory; this.providerFactory = providerFactory; + this.fileSystemOperations = fileSystemOperations; } @Override @@ -76,7 +82,8 @@ public void apply(Project project) { providerFactory, objectFactory, toolChainService, - isCi + isCi, + fileSystemOperations ); }); } @@ -88,7 +95,8 @@ private static void configureBwcProject( ProviderFactory providerFactory, ObjectFactory objectFactory, JavaToolchainService toolChainService, - Boolean isCi + Boolean isCi, + FileSystemOperations fileSystemOperations ) { ProjectLayout layout = project.getLayout(); Provider versionInfoProvider = providerFactory.provider(() -> versionInfo); @@ -120,11 +128,30 @@ private static void configureBwcProject( List distributionProjects = resolveArchiveProjects(checkoutDir.get(), bwcVersion.get()); // Setup gradle user home directory - project.getTasks().register("setupGradleUserHome", Copy.class, copy -> { - copy.into(project.getGradle().getGradleUserHomeDir().getAbsolutePath() + "-" + project.getName()); - copy.from(project.getGradle().getGradleUserHomeDir().getAbsolutePath(), copySpec -> { - copySpec.include("gradle.properties"); - copySpec.include("init.d/*"); + // We manually setup input/outputs here to avoid having the entire gradle user home directory as an output directory, as that + // makes task output snapshotting very expensive + project.getTasks().register("setupGradleUserHome", task -> { + task.getInputs() + .file(new File(project.getGradle().getGradleUserHomeDir().getAbsolutePath(), "gradle.properties")) + .withPathSensitivity(PathSensitivity.NONE); + task.getInputs() + .dir(new File(project.getGradle().getGradleUserHomeDir().getAbsolutePath(), "init.d")) + .withPathSensitivity(PathSensitivity.NONE); + task.getOutputs() + .file( + new File(project.getGradle().getGradleUserHomeDir().getAbsolutePath() + "-" + project.getName(), "gradle.properties") + ); + task.getOutputs() + .dir(new File(project.getGradle().getGradleUserHomeDir().getAbsolutePath() + "-" + project.getName(), "init.d")); + + task.doLast(t -> { + fileSystemOperations.copy(copy -> { + copy.into(project.getGradle().getGradleUserHomeDir().getAbsolutePath() + "-" + project.getName()); + copy.from(project.getGradle().getGradleUserHomeDir().getAbsolutePath(), copySpec -> { + copySpec.include("gradle.properties"); + copySpec.include("init.d/*"); + }); + }); }); });