Skip to content

Commit

Permalink
Improve efficiency of incremental builds when building bwc distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Dec 13, 2024
1 parent f900ae6 commit 3999f6e
Showing 1 changed file with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,11 +54,17 @@ public class InternalDistributionBwcSetupPlugin implements Plugin<Project> {
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
Expand All @@ -76,7 +82,8 @@ public void apply(Project project) {
providerFactory,
objectFactory,
toolChainService,
isCi
isCi,
fileSystemOperations
);
});
}
Expand All @@ -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<BwcVersions.UnreleasedVersionInfo> versionInfoProvider = providerFactory.provider(() -> versionInfo);
Expand Down Expand Up @@ -120,11 +128,30 @@ private static void configureBwcProject(
List<DistributionProject> 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/*");
});
});
});
});

Expand Down

0 comments on commit 3999f6e

Please sign in to comment.