diff --git a/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/DevelocityConventions.java b/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/DevelocityConventions.java index 3a94e0792..7e6e1ea2e 100644 --- a/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/DevelocityConventions.java +++ b/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/DevelocityConventions.java @@ -10,6 +10,7 @@ void configureDevelocity(DevelocityConfigurable develocity) { // CHANGE ME: Apply your Develocity configuration here develocity.setServer("https://develocity-samples.gradle.com"); configureBuildScan(develocity.getBuildScan()); + configureBuildCache(develocity.getBuildCache()); } private void configureBuildScan(BuildScanConfigurable buildScan) { @@ -17,7 +18,7 @@ private void configureBuildScan(BuildScanConfigurable buildScan) { buildScan.setUploadInBackground(!isCi()); } - void configureBuildCache(BuildCacheConfigurable buildCache) { + private void configureBuildCache(BuildCacheConfigurable buildCache) { // CHANGE ME: Apply your Build Cache configuration here buildCache.getLocal().setEnabled(true); buildCache.getLocal().setStoreEnabled(true); diff --git a/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/configurable/DevelocityConfigurable.java b/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/configurable/DevelocityConfigurable.java index e9d67d083..48ddd8314 100644 --- a/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/configurable/DevelocityConfigurable.java +++ b/convention-develocity-shared/convention-develocity-common/src/main/java/com/myorg/configurable/DevelocityConfigurable.java @@ -12,4 +12,6 @@ public interface DevelocityConfigurable { BuildScanConfigurable getBuildScan(); + BuildCacheConfigurable getBuildCache(); + } diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java index 160d6bdd6..3d6c5405e 100644 --- a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java @@ -3,7 +3,6 @@ import com.gradle.CommonCustomUserDataGradlePlugin; import com.gradle.develocity.agent.gradle.DevelocityConfiguration; import com.gradle.develocity.agent.gradle.DevelocityPlugin; -import com.myorg.configurable.GradleBuildCacheConfigurable; import com.myorg.configurable.GradleDevelocityConfigurable; import org.gradle.api.GradleException; import org.gradle.api.Plugin; @@ -41,20 +40,15 @@ public void apply(Object target) { private void configureGradle6OrNewer(Settings settings) { settings.getPluginManager().apply(DevelocityPlugin.class); settings.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class); - DevelocityConfiguration develocity = settings.getExtensions().getByType(DevelocityConfiguration.class); - DevelocityConventions develocityConventions = new DevelocityConventions(); - develocityConventions.configureDevelocity(new GradleDevelocityConfigurable(develocity)); - develocityConventions.configureBuildCache(new GradleBuildCacheConfigurable(develocity.getBuildCache(), settings.getBuildCache())); + new DevelocityConventions().configureDevelocity(new GradleDevelocityConfigurable(develocity, settings.getBuildCache())); } private void configureGradle5(Project project) { project.getPluginManager().apply(DevelocityPlugin.class); project.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class); - - DevelocityConventions develocityConventions = new DevelocityConventions(); - develocityConventions.configureDevelocity(new GradleDevelocityConfigurable(project.getExtensions().getByType(DevelocityConfiguration.class))); - // develocityConventions.configureBuildCache is not called because the build cache cannot be configured via a plugin prior to Gradle 6.0 + DevelocityConfiguration develocity = project.getExtensions().getByType(DevelocityConfiguration.class); + new DevelocityConventions().configureDevelocity(new GradleDevelocityConfigurable(develocity)); } private static boolean isGradle6OrNewer() { diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleBuildCacheConfigurable.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleBuildCacheConfigurable.java index aefedd164..c376e3a8a 100644 --- a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleBuildCacheConfigurable.java +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleBuildCacheConfigurable.java @@ -3,7 +3,7 @@ import com.gradle.develocity.agent.gradle.buildcache.DevelocityBuildCache; import org.gradle.caching.configuration.BuildCacheConfiguration; -public final class GradleBuildCacheConfigurable implements BuildCacheConfigurable { +final class GradleBuildCacheConfigurable implements BuildCacheConfigurable { private final LocalBuildCacheConfigurable localBuildCache; private final RemoteBuildCacheConfigurable remoteBuildCache; diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleDevelocityConfigurable.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleDevelocityConfigurable.java index 030ae1fc9..afe9a8290 100644 --- a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleDevelocityConfigurable.java +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleDevelocityConfigurable.java @@ -1,15 +1,24 @@ package com.myorg.configurable; import com.gradle.develocity.agent.gradle.DevelocityConfiguration; +import org.gradle.caching.configuration.BuildCacheConfiguration; public final class GradleDevelocityConfigurable implements DevelocityConfigurable { private final DevelocityConfiguration develocity; private final BuildScanConfigurable buildScan; + private final BuildCacheConfigurable buildCache; public GradleDevelocityConfigurable(DevelocityConfiguration develocity) { this.develocity = develocity; this.buildScan = new GradleBuildScanConfigurable(develocity.getBuildScan()); + this.buildCache = new NoopBuildCacheConfigurable(); + } + + public GradleDevelocityConfigurable(DevelocityConfiguration develocity, BuildCacheConfiguration buildCache) { + this.develocity = develocity; + this.buildScan = new GradleBuildScanConfigurable(develocity.getBuildScan()); + this.buildCache = new GradleBuildCacheConfigurable(develocity.getBuildCache(), buildCache); } @Override @@ -37,4 +46,9 @@ public BuildScanConfigurable getBuildScan() { return buildScan; } + @Override + public BuildCacheConfigurable getBuildCache() { + return buildCache; + } + } diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopBuildCacheConfigurable.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopBuildCacheConfigurable.java new file mode 100644 index 000000000..91bf65d97 --- /dev/null +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopBuildCacheConfigurable.java @@ -0,0 +1,19 @@ +package com.myorg.configurable; + +/* + * Build cache cannot be configured via a plugin prior to Gradle 6.0, so build + * cache operations must be a no-op. + */ +final class NoopBuildCacheConfigurable implements BuildCacheConfigurable { + + @Override + public LocalBuildCacheConfigurable getLocal() { + return new NoopLocalBuildCacheConfigurable(); + } + + @Override + public RemoteBuildCacheConfigurable getRemote() { + return new NoopRemoteBuildCacheConfigurable(); + } + +} diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopLocalBuildCacheConfigurable.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopLocalBuildCacheConfigurable.java new file mode 100644 index 000000000..da082991d --- /dev/null +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopLocalBuildCacheConfigurable.java @@ -0,0 +1,26 @@ +package com.myorg.configurable; + +import java.io.File; + +/* + * Build cache cannot be configured via a plugin prior to Gradle 6.0, so build + * cache operations must be a no-op. + */ +final class NoopLocalBuildCacheConfigurable implements LocalBuildCacheConfigurable { + + @Override + public void setEnabled(boolean enabled) { + + } + + @Override + public void setStoreEnabled(boolean storeEnabled) { + + } + + @Override + public void setDirectory(File directory) { + + } + +} diff --git a/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopRemoteBuildCacheConfigurable.java b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopRemoteBuildCacheConfigurable.java new file mode 100644 index 000000000..335cb0848 --- /dev/null +++ b/convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/NoopRemoteBuildCacheConfigurable.java @@ -0,0 +1,19 @@ +package com.myorg.configurable; + +/* + * Build cache cannot be configured via a plugin prior to Gradle 6.0, so build + * cache operations must be a no-op. + */ +final class NoopRemoteBuildCacheConfigurable implements RemoteBuildCacheConfigurable { + + @Override + public void setEnabled(boolean enabled) { + + } + + @Override + public void setStoreEnabled(boolean storeEnabled) { + + } + +} diff --git a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/ConventionDevelocityMavenExtensionListener.java b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/ConventionDevelocityMavenExtensionListener.java index 57331fea8..f0567374d 100644 --- a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/ConventionDevelocityMavenExtensionListener.java +++ b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/ConventionDevelocityMavenExtensionListener.java @@ -2,7 +2,6 @@ import com.gradle.develocity.agent.maven.api.DevelocityApi; import com.gradle.develocity.agent.maven.api.DevelocityListener; -import com.myorg.configurable.MavenBuildCacheConfigurable; import com.myorg.configurable.MavenDevelocityConfigurable; import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.component.annotations.Component; @@ -19,9 +18,7 @@ final class ConventionDevelocityMavenExtensionListener implements DevelocityList @Override public void configure(DevelocityApi develocity, MavenSession session) { - DevelocityConventions develocityConventions = new DevelocityConventions(); - develocityConventions.configureDevelocity(new MavenDevelocityConfigurable(develocity)); - develocityConventions.configureBuildCache(new MavenBuildCacheConfigurable(develocity.getBuildCache())); + new DevelocityConventions().configureDevelocity(new MavenDevelocityConfigurable(develocity)); } } diff --git a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenBuildCacheConfigurable.java b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenBuildCacheConfigurable.java index a911af6cc..d17a7c753 100644 --- a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenBuildCacheConfigurable.java +++ b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenBuildCacheConfigurable.java @@ -2,7 +2,7 @@ import com.gradle.develocity.agent.maven.api.cache.BuildCacheApi; -public final class MavenBuildCacheConfigurable implements BuildCacheConfigurable { +final class MavenBuildCacheConfigurable implements BuildCacheConfigurable { private final LocalBuildCacheConfigurable localBuildCache; private final RemoteBuildCacheConfigurable remoteBuildCache; diff --git a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenDevelocityConfigurable.java b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenDevelocityConfigurable.java index dbaacf0c0..7ea384a62 100644 --- a/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenDevelocityConfigurable.java +++ b/convention-develocity-shared/convention-develocity-maven-extension/src/main/java/com/myorg/configurable/MavenDevelocityConfigurable.java @@ -6,10 +6,12 @@ public final class MavenDevelocityConfigurable implements DevelocityConfigurable private final DevelocityApi develocity; private final BuildScanConfigurable buildScan; + private final BuildCacheConfigurable buildCache; public MavenDevelocityConfigurable(DevelocityApi develocity) { this.develocity = develocity; this.buildScan = new MavenBuildScanConfigurable(develocity.getBuildScan()); + this.buildCache = new MavenBuildCacheConfigurable(develocity.getBuildCache()); } @Override @@ -37,4 +39,9 @@ public BuildScanConfigurable getBuildScan() { return buildScan; } + @Override + public BuildCacheConfigurable getBuildCache() { + return buildCache; + } + }