Skip to content

Commit 6a01437

Browse files
committed
Update environment variables to avoid deprecation warning
See gh-73 See gh-74
1 parent 2433931 commit 6a01437

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Diff for: README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ When applied, the conventions will configure the build cache to:
1616
#### URL
1717

1818
By default, https://ge.spring.io will be used as the remote cache server.
19-
The server can be configured using the `GRADLE_ENTERPRISE_CACHE_SERVER` environment variable.
19+
The server can be configured using the `DEVELOCITY_CACHE_SERVER` environment variable.
2020
For backwards compatibility, `GRADLE_ENTERPRISE_CACHE_URL` is also supported for a limited time.
2121
`/cache/` is removed from the end of the URL and the remainder is used to configure the remote cache server.
2222

@@ -57,7 +57,8 @@ When using Gradle, build scans can be published anonymously to scans.gradle.com
5757

5858
Publishing build scans and pushing to the remote cache requires authentication via an access key.
5959
Additionally, pushing to the remote cache also requires that a CI environment be detected.
60-
When running on CI, the access key should be made available via the `GRADLE_ENTERPRISE_ACCESS_KEY` environment variable.
60+
When running on CI, the access key should be made available via the `DEVELOCITY_ACCESS_KEY` environment variable.
61+
`GRADLE_ENTERPRISE_ACCESS_KEY` can also be used although it will result in a deprecation warning from Gradle.
6162

6263
#### Bamboo
6364

@@ -77,7 +78,7 @@ The environment variable should be set using the `gradle_enterprise_secret_acces
7778

7879
#### Local
7980

80-
An access key can be provisioned by running `./gradlew provisionGradleEnterpriseAccessKey` once the project has been configured to use this plugin.
81+
An access key can be provisioned by running `./gradlew provisionDevelocityAccessKey` once the project has been configured to use this plugin.
8182

8283
## Detecting CI
8384

Diff for: src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ public void execute(BuildCacheConfiguration buildCache) {
4949
buildCache.local((local) -> local.setEnabled(true));
5050
buildCache.remote(this.buildCacheType, (remote) -> {
5151
remote.setEnabled(true);
52-
String cacheServer = this.env.get("GRADLE_ENTERPRISE_CACHE_SERVER");
52+
String cacheServer = this.env.get("DEVELOCITY_CACHE_SERVER");
5353
if (cacheServer == null) {
5454
cacheServer = serverOfCacheUrl(this.env.get("GRADLE_ENTERPRISE_CACHE_URL"));
5555
if (cacheServer == null) {
5656
cacheServer = "https://ge.spring.io";
5757
}
5858
}
5959
remote.setServer(cacheServer);
60-
String accessKey = this.env.get("GRADLE_ENTERPRISE_ACCESS_KEY");
60+
String accessKey = this.env.get("DEVELOCITY_ACCESS_KEY");
61+
if (accessKey == null) {
62+
accessKey = this.env.get("GRADLE_ENTERPRISE_ACCESS_KEY");
63+
}
6164
if (hasText(accessKey) && ContinuousIntegration.detect(this.env) != null) {
6265
remote.setPush(true);
6366
}

Diff for: src/test/java/io/spring/ge/conventions/gradle/BuildCacheConventionsTests.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void remoteCacheUrlCanBeConfigured(String cacheUrl) {
6969
@Test
7070
void remoteCacheServerCanBeConfigured() {
7171
Map<String, String> env = new HashMap<>();
72-
env.put("GRADLE_ENTERPRISE_CACHE_SERVER", "https://ge.example.com");
72+
env.put("DEVELOCITY_CACHE_SERVER", "https://ge.example.com");
7373
new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache);
7474
assertThat(this.buildCache.remote.isEnabled()).isTrue();
7575
assertThat(this.buildCache.remote.getServer()).isEqualTo("https://ge.example.com");
@@ -80,7 +80,7 @@ void remoteCacheServerCanBeConfigured() {
8080
void remoteCacheServerHasPrecedenceOverRemoteCacheUrl() {
8181
Map<String, String> env = new HashMap<>();
8282
env.put("GRADLE_ENTERPRISE_CACHE_URL", "https://ge-cache.example.com/cache/");
83-
env.put("GRADLE_ENTERPRISE_CACHE_SERVER", "https://ge.example.com");
83+
env.put("DEVELOCITY_CACHE_SERVER", "https://ge.example.com");
8484
new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache);
8585
assertThat(this.buildCache.remote.isEnabled()).isTrue();
8686
assertThat(this.buildCache.remote.getServer()).isEqualTo("https://ge.example.com");
@@ -90,13 +90,30 @@ void remoteCacheServerHasPrecedenceOverRemoteCacheUrl() {
9090
@Test
9191
void whenAccessTokenIsProvidedInALocalEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() {
9292
new BuildCacheConventions(DevelocityBuildCache.class,
93-
Collections.singletonMap("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4"))
93+
Collections.singletonMap("DEVELOCITY_ACCESS_KEY", "ge.example.com=a1b2c3d4"))
9494
.execute(this.buildCache);
9595
assertThat(this.buildCache.remote.isPush()).isFalse();
9696
}
9797

9898
@Test
9999
void whenAccessTokenIsProvidedInACiEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() {
100+
Map<String, String> env = new HashMap<>();
101+
env.put("DEVELOCITY_ACCESS_KEY", "ge.example.com=a1b2c3d4");
102+
env.put("CI", "true");
103+
new BuildCacheConventions(DevelocityBuildCache.class, env).execute(this.buildCache);
104+
assertThat(this.buildCache.remote.isPush()).isTrue();
105+
}
106+
107+
@Test
108+
void whenLegacyAccessTokenIsProvidedInALocalEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() {
109+
new BuildCacheConventions(DevelocityBuildCache.class,
110+
Collections.singletonMap("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4"))
111+
.execute(this.buildCache);
112+
assertThat(this.buildCache.remote.isPush()).isFalse();
113+
}
114+
115+
@Test
116+
void whenLegacyAccessTokenIsProvidedInACiEnvironmentThenPushingToTheRemoteCacheIsNotEnabled() {
100117
Map<String, String> env = new HashMap<>();
101118
env.put("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4");
102119
env.put("CI", "true");

0 commit comments

Comments
 (0)