From 6a01437cea21dded42aa78c2d25b1a11c3369b9e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 25 Apr 2024 16:53:04 +0100 Subject: [PATCH] Update environment variables to avoid deprecation warning See gh-73 See gh-74 --- README.md | 7 +++--- .../gradle/BuildCacheConventions.java | 7 ++++-- .../gradle/BuildCacheConventionsTests.java | 23 ++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 52deca5..2a01f92 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ When applied, the conventions will configure the build cache to: #### URL By default, https://ge.spring.io will be used as the remote cache server. -The server can be configured using the `GRADLE_ENTERPRISE_CACHE_SERVER` environment variable. +The server can be configured using the `DEVELOCITY_CACHE_SERVER` environment variable. For backwards compatibility, `GRADLE_ENTERPRISE_CACHE_URL` is also supported for a limited time. `/cache/` is removed from the end of the URL and the remainder is used to configure the remote cache server. @@ -57,7 +57,8 @@ When using Gradle, build scans can be published anonymously to scans.gradle.com Publishing build scans and pushing to the remote cache requires authentication via an access key. Additionally, pushing to the remote cache also requires that a CI environment be detected. -When running on CI, the access key should be made available via the `GRADLE_ENTERPRISE_ACCESS_KEY` environment variable. +When running on CI, the access key should be made available via the `DEVELOCITY_ACCESS_KEY` environment variable. +`GRADLE_ENTERPRISE_ACCESS_KEY` can also be used although it will result in a deprecation warning from Gradle. #### Bamboo @@ -77,7 +78,7 @@ The environment variable should be set using the `gradle_enterprise_secret_acces #### Local -An access key can be provisioned by running `./gradlew provisionGradleEnterpriseAccessKey` once the project has been configured to use this plugin. +An access key can be provisioned by running `./gradlew provisionDevelocityAccessKey` once the project has been configured to use this plugin. ## Detecting CI diff --git a/src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java b/src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java index 243081e..46fbc65 100644 --- a/src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java +++ b/src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java @@ -49,7 +49,7 @@ public void execute(BuildCacheConfiguration buildCache) { buildCache.local((local) -> local.setEnabled(true)); buildCache.remote(this.buildCacheType, (remote) -> { remote.setEnabled(true); - String cacheServer = this.env.get("GRADLE_ENTERPRISE_CACHE_SERVER"); + String cacheServer = this.env.get("DEVELOCITY_CACHE_SERVER"); if (cacheServer == null) { cacheServer = serverOfCacheUrl(this.env.get("GRADLE_ENTERPRISE_CACHE_URL")); if (cacheServer == null) { @@ -57,7 +57,10 @@ public void execute(BuildCacheConfiguration buildCache) { } } remote.setServer(cacheServer); - String accessKey = this.env.get("GRADLE_ENTERPRISE_ACCESS_KEY"); + String accessKey = this.env.get("DEVELOCITY_ACCESS_KEY"); + if (accessKey == null) { + accessKey = this.env.get("GRADLE_ENTERPRISE_ACCESS_KEY"); + } if (hasText(accessKey) && ContinuousIntegration.detect(this.env) != null) { remote.setPush(true); } diff --git a/src/test/java/io/spring/ge/conventions/gradle/BuildCacheConventionsTests.java b/src/test/java/io/spring/ge/conventions/gradle/BuildCacheConventionsTests.java index 9bb658a..80d0166 100644 --- a/src/test/java/io/spring/ge/conventions/gradle/BuildCacheConventionsTests.java +++ b/src/test/java/io/spring/ge/conventions/gradle/BuildCacheConventionsTests.java @@ -69,7 +69,7 @@ void remoteCacheUrlCanBeConfigured(String cacheUrl) { @Test void remoteCacheServerCanBeConfigured() { Map env = new HashMap<>(); - env.put("GRADLE_ENTERPRISE_CACHE_SERVER", "https://ge.example.com"); + env.put("DEVELOCITY_CACHE_SERVER", "https://ge.example.com"); new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache); assertThat(this.buildCache.remote.isEnabled()).isTrue(); assertThat(this.buildCache.remote.getServer()).isEqualTo("https://ge.example.com"); @@ -80,7 +80,7 @@ void remoteCacheServerCanBeConfigured() { void remoteCacheServerHasPrecedenceOverRemoteCacheUrl() { Map env = new HashMap<>(); env.put("GRADLE_ENTERPRISE_CACHE_URL", "https://ge-cache.example.com/cache/"); - env.put("GRADLE_ENTERPRISE_CACHE_SERVER", "https://ge.example.com"); + env.put("DEVELOCITY_CACHE_SERVER", "https://ge.example.com"); new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache); assertThat(this.buildCache.remote.isEnabled()).isTrue(); assertThat(this.buildCache.remote.getServer()).isEqualTo("https://ge.example.com"); @@ -90,13 +90,30 @@ void remoteCacheServerHasPrecedenceOverRemoteCacheUrl() { @Test void whenAccessTokenIsProvidedInALocalEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() { new BuildCacheConventions(DevelocityBuildCache.class, - Collections.singletonMap("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4")) + Collections.singletonMap("DEVELOCITY_ACCESS_KEY", "ge.example.com=a1b2c3d4")) .execute(this.buildCache); assertThat(this.buildCache.remote.isPush()).isFalse(); } @Test void whenAccessTokenIsProvidedInACiEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() { + Map env = new HashMap<>(); + env.put("DEVELOCITY_ACCESS_KEY", "ge.example.com=a1b2c3d4"); + env.put("CI", "true"); + new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache); + assertThat(this.buildCache.remote.isPush()).isTrue(); + } + + @Test + void whenLegacyAccessTokenIsProvidedInALocalEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() { + new BuildCacheConventions(DevelocityBuildCache.class, + Collections.singletonMap("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4")) + .execute(this.buildCache); + assertThat(this.buildCache.remote.isPush()).isFalse(); + } + + @Test + void whenLegacyAccessTokenIsProvidedInACiEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() { Map env = new HashMap<>(); env.put("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4"); env.put("CI", "true");