Skip to content

Commit

Permalink
Update environment variables to avoid deprecation warning
Browse files Browse the repository at this point in the history
See gh-73
See gh-74
  • Loading branch information
wilkinsona committed Apr 25, 2024
1 parent 2433931 commit 6a01437
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ 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) {
cacheServer = "https://ge.spring.io";
}
}
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void remoteCacheUrlCanBeConfigured(String cacheUrl) {
@Test
void remoteCacheServerCanBeConfigured() {
Map<String, String> 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");
Expand All @@ -80,7 +80,7 @@ void remoteCacheServerCanBeConfigured() {
void remoteCacheServerHasPrecedenceOverRemoteCacheUrl() {
Map<String, String> 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");
Expand All @@ -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<String, String> 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<String, String> env = new HashMap<>();
env.put("GRADLE_ENTERPRISE_ACCESS_KEY", "ge.example.com=a1b2c3d4");
env.put("CI", "true");
Expand Down

0 comments on commit 6a01437

Please sign in to comment.