From 1a54b83ae1477172f9073f72479c1d0ae13bbfc9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 29 Oct 2019 11:46:33 +0000 Subject: [PATCH] Add opt-in support for remote build cache and pushing to it from CI This commit provides opt-in enablement of Gradle's remote build cache. When the GRADLE_ENTERPRISE_URL environment variable is set, its build cache node will be used as a source of cached output. If both GRADLE_ENTERPRISE_CACHE_USERNAME and GRADLE_ENTERPRISE_CACHE_PASSWORD are also set, task output produced by the build will be pushed to the build cache node for use by subsequent builds. Closes gh-23883 --- gradle/build-cache-settings.gradle | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gradle/build-cache-settings.gradle b/gradle/build-cache-settings.gradle index b143a54a09..d62ea57ebd 100644 --- a/gradle/build-cache-settings.gradle +++ b/gradle/build-cache-settings.gradle @@ -2,7 +2,19 @@ buildCache { local { enabled = true } - remote(HttpBuildCache) { - enabled = false + if (System.getenv('GRADLE_ENTERPRISE_URL')) { + remote(HttpBuildCache) { + enabled = true + url = "${System.getenv('GRADLE_ENTERPRISE_URL')}/cache/" + def cacheUsername = System.getenv('GRADLE_ENTERPRISE_CACHE_USERNAME') + def cachePassword = System.getenv('GRADLE_ENTERPRISE_CACHE_PASSWORD') + if (cacheUsername && cachePassword) { + push = true + credentials { + username = cacheUsername + password = cachePassword + } + } + } } }