From 8dfe7f2373ef29f0555c805d7455c7f279f999f9 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 22 Feb 2024 17:59:07 +0100 Subject: [PATCH] Use Access Key based authentication via Develocity Connector This migrates the access to the Develocity Build Cache to use Access Key based authentication instead of username and password authentication. This means that the access will use the same access key as is is used for Build Scan publication. Here is more information on the Develocity Connector [see here](https://docs.gradle.com/enterprise/gradle-plugin/#using_the_develocity_connector) --- .../actions/build-single-project/action.yml | 2 -- .github/workflows/presubmit.yml | 3 -- buildSrc/settings.gradle | 22 +++++++++++++++ gradle/verification-metadata.xml | 21 ++++++++++++++ .../playground-plugin/build.gradle | 4 +-- .../playground-plugin/settings.gradle | 28 ++++++++++--------- .../GradleEnterpriseConventionsPlugin.kt | 17 +++-------- settings.gradle | 2 -- 8 files changed, 64 insertions(+), 35 deletions(-) diff --git a/.github/actions/build-single-project/action.yml b/.github/actions/build-single-project/action.yml index feef143803d28..a58c6e0ed7cd2 100644 --- a/.github/actions/build-single-project/action.yml +++ b/.github/actions/build-single-project/action.yml @@ -61,7 +61,6 @@ runs: - name: "gradle buildOnServer zipTestConfigsWithApks" env: JAVA_HOME: ${{ steps.setup-java.outputs.path }} - GRADLE_BUILD_CACHE_PASSWORD: ${{ inputs.gradle-cache-password }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-access-key }} GRADLE_ENCRYPTION_KEY: ${{ inputs.gradle-encryption-key }} working-directory: ${{ inputs.project-root }} @@ -70,7 +69,6 @@ runs: - name: "gradle playgroundCIHostTests" env: JAVA_HOME: ${{ steps.setup-java.outputs.path }} - GRADLE_BUILD_CACHE_PASSWORD: ${{ inputs.gradle-cache-password }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-access-key }} GRADLE_ENCRYPTION_KEY: ${{ inputs.gradle-encryption-key }} working-directory: ${{ inputs.project-root }} diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 8261313bcf5ed..828ab392c984c 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -36,7 +36,6 @@ jobs: status: ${{ steps.output-status.outputs.status }} affectedFileArgs: ${{ steps.affected-file-args.outputs.files }} env: - GRADLE_BUILD_CACHE_PASSWORD: ${{ secrets.GRADLE_BUILD_CACHE_PASSWORD }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }} steps: @@ -130,7 +129,6 @@ jobs: env: artifact-id: ${{matrix.project}} project-root: playground-projects/${{matrix.project-root || matrix.project}}-playground - GRADLE_BUILD_CACHE_PASSWORD: ${{ secrets.GRADLE_BUILD_CACHE_PASSWORD }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }} steps: @@ -150,7 +148,6 @@ jobs: with: project: ${{ matrix.project }} project-root: ${{ env.project-root }} - gradle-cache-password: ${{ secrets.GRADLE_BUILD_CACHE_PASSWORD }} gradle-enterprise-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} gradle-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} gradle-flags: ${{ needs.setup.outputs.gradlew_flags }} diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle index 68c85829b52c9..d4dee34d93edf 100644 --- a/buildSrc/settings.gradle +++ b/buildSrc/settings.gradle @@ -14,6 +14,10 @@ * limitations under the License. */ +plugins { + id 'com.gradle.enterprise' version "3.16.2" +} + include ":jetpad-integration" include ":plugins" include ":private" @@ -42,3 +46,21 @@ dependencyResolutionManagement { } } } +def isCI = System.getenv("CI") == "true" + +gradleEnterprise { + server = "https://ge.androidx.dev" +} + +buildCache { + local { + // Aggressively clean up stale build cache entries on CI + if (isCI) { + removeUnusedEntriesAfterDays = 1 + } + } + remote(gradleEnterprise.buildCache) { + def accessKey = System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY") + push = isCI && accessKey + } +} diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index d058dab2e69be..8c2ce3bc16f37 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -651,6 +651,27 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/playground-common/playground-plugin/build.gradle b/playground-common/playground-plugin/build.gradle index cc6735b115a6a..1e0886c1eeecb 100644 --- a/playground-common/playground-plugin/build.gradle +++ b/playground-common/playground-plugin/build.gradle @@ -21,8 +21,8 @@ plugins { dependencies { implementation(project(":shared")) - implementation("com.gradle:gradle-enterprise-gradle-plugin:3.16") - implementation("com.gradle:common-custom-user-data-gradle-plugin:1.12") + implementation("com.gradle:gradle-enterprise-gradle-plugin:3.16.2") + implementation("com.gradle:common-custom-user-data-gradle-plugin:1.13") implementation("supportBuildSrc:private") implementation("supportBuildSrc:public") implementation("supportBuildSrc:plugins") diff --git a/playground-common/playground-plugin/settings.gradle b/playground-common/playground-plugin/settings.gradle index 318d4020fbe40..8de737dac523c 100644 --- a/playground-common/playground-plugin/settings.gradle +++ b/playground-common/playground-plugin/settings.gradle @@ -20,10 +20,16 @@ pluginManagement { google() gradlePluginPortal().content { it.includeModule("org.jetbrains.kotlin.jvm", "org.jetbrains.kotlin.jvm.gradle.plugin") + it.includeModule("com.gradle.enterprise", "com.gradle.enterprise.gradle.plugin") + it.includeModule("com.gradle", "gradle-enterprise-gradle-plugin") } } } +plugins { + id("com.gradle.enterprise") version "3.16.2" +} + dependencyResolutionManagement { repositories { mavenCentral() @@ -59,6 +65,11 @@ include(":shared") // so that when building the `playground-plugin` included build the same build cache settings will be used. // Without this, Gradle Enterprise erroneously reports a problem with 'buildSrc' build cache configuration. def isCI = System.getenv("CI") == "true" + +gradleEnterprise { + server = "https://ge.androidx.dev" +} + buildCache { local { // Aggressively clean up stale build cache entries on CI @@ -66,17 +77,8 @@ buildCache { removeUnusedEntriesAfterDays = 1 } } - remote(HttpBuildCache) { - url = "https://ge.androidx.dev/cache/" - var buildCachePassword = System.getenv("GRADLE_BUILD_CACHE_PASSWORD") - if (isCI && buildCachePassword != null && !buildCachePassword.empty) { - push = true - credentials { - username = "ci" - password = buildCachePassword - } - } else { - push = false - } - } + remote(gradleEnterprise.buildCache) { + def accessKey = System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY") + push = isCI && accessKey + } } diff --git a/playground-common/playground-plugin/src/main/kotlin/androidx/playground/GradleEnterpriseConventionsPlugin.kt b/playground-common/playground-plugin/src/main/kotlin/androidx/playground/GradleEnterpriseConventionsPlugin.kt index aa5351fee201f..48f11bad0c053 100644 --- a/playground-common/playground-plugin/src/main/kotlin/androidx/playground/GradleEnterpriseConventionsPlugin.kt +++ b/playground-common/playground-plugin/src/main/kotlin/androidx/playground/GradleEnterpriseConventionsPlugin.kt @@ -19,7 +19,6 @@ package androidx.playground import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures import org.gradle.api.Plugin import org.gradle.api.initialization.Settings -import org.gradle.caching.http.HttpBuildCache import org.gradle.kotlin.dsl.gradleEnterprise import java.net.InetAddress import java.net.URI @@ -54,18 +53,10 @@ class GradleEnterpriseConventionsPlugin : Plugin { } } - settings.buildCache.remote(HttpBuildCache::class.java) { remote -> - remote.url = URI("https://ge.androidx.dev/cache/") - val buildCachePassword = System.getenv("GRADLE_BUILD_CACHE_PASSWORD") - if (isCI && !buildCachePassword.isNullOrEmpty()) { - remote.isPush = true - remote.credentials { credentials -> - credentials.username = "ci" - credentials.password = buildCachePassword - } - } else { - remote.isPush = false - } + settings.buildCache.remote(settings.gradleEnterprise.buildCache) { remote -> + val develocityAccessKey = System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY") + remote.setEnabled(true) + remote.isPush = isCI && !develocityAccessKey.isNullOrEmpty() } } diff --git a/settings.gradle b/settings.gradle index 1452ce505bb9e..56258ef894b63 100644 --- a/settings.gradle +++ b/settings.gradle @@ -30,8 +30,6 @@ buildscript { classpath("com.google.protobuf:protobuf-java:3.22.3") // upgrade okio for gcpbuildcache that is compatible with the wire plugin used by androidx classpath("com.squareup.okio:okio:3.3.0") - classpath("com.gradle:gradle-enterprise-gradle-plugin:3.16") - classpath("com.gradle:common-custom-user-data-gradle-plugin:1.12") classpath("androidx.build.gradle.gcpbuildcache:gcpbuildcache:1.0.0-beta07") } }