From 07dc9682b9cf99675881d8f2cfc84f275d90f4bd Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 22:41:15 +0300 Subject: [PATCH] Cache the downloads of the Gradle plugins' TestKit builds The TestKit builds of the Gradle plugins' tests have a Gradle user home of their own, under build/tmp/test/work by default, which CI's cache does not reach. Every job that runs those tests downloaded the Android Gradle plugin and its dependencies, about 127 MB, from Maven Central again: eight jobs a push, and on 2026-11-28 two pushes three minutes apart got 429 Too Many Requests from Maven Central. -PtestkitDir now sets that home. CI points it at test-kit in the Gradle user home and adds test-kit/caches/modules-2 to the paths setup-gradle caches. Locally the default stays: one directory for every checkout would be shared by tests that delete from it. MultiProjectTest's library with variants is looked for in its own repository only. The root project asked Maven Central for it first, which failed that test on a 429 as well. --- .github/workflows/ci.yml | 34 +++++++++++++++---- gradle-open-java-format/build.gradle | 9 +++++ .../javaformat/gradle/MultiProjectTest.java | 11 +++++- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4d78e5dc..1acc75a68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,19 +39,27 @@ jobs: # on 2026-10-19). Only builds of the default branch write the cache; pull requests read it. Two # things stay out: the local build cache, left out on purpose for now, and the IDE the IntelliJ # plugin's tests start, whose 852 MB zip and the 2.1 GB it unpacks to under transforms would take - # longer to restore than to download and fill much of the repository's 10 GB. Leaving paths out is a - # feature of the default, proprietary cache provider, bundled in the action and free for public - # repositories; the open-source one has none. + # longer to restore than to download and fill much of the repository's 10 GB. One thing goes in besides + # the default `caches` and `notifications`: the downloads of the Gradle plugins' TestKit builds, the + # Android Gradle plugin and its dependencies above all. Those builds have a Gradle user home of their + # own, under build/tmp by default, which the cache did not reach: every job downloaded it all from + # Maven Central again, until Maven Central answered 429 Too Many Requests on 2026-11-28. -PtestkitDir + # puts that home at test-kit in this one. Choosing paths is a feature of the default, proprietary + # cache provider, bundled in the action and free for public repositories; the open-source one has none. - name: Cache Gradle's downloads uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 with: + gradle-home-cache-includes: | + caches + notifications + test-kit/caches/modules-2 gradle-home-cache-excludes: | caches/build-cache-1 caches/modules-2/files-2.1/com.jetbrains.intellij.idea caches/*/transforms - name: Build - run: ./gradlew check + run: ./gradlew check -PtestkitDir="$GRADLE_USER_HOME/test-kit" - name: Publish Test Report uses: mikepenz/action-junit-report@a16be3a69023e9bd7e748ede768b3282ea7b30ce # v6.7.1 @@ -125,6 +133,10 @@ jobs: - name: Cache Gradle's downloads uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 with: + gradle-home-cache-includes: | + caches + notifications + test-kit/caches/modules-2 gradle-home-cache-excludes: | caches/build-cache-1 caches/modules-2/files-2.1/com.jetbrains.intellij.idea @@ -147,7 +159,7 @@ jobs: TESTKIT_GRADLE: ${{ matrix.gradle }} run: >- ./gradlew test -PjavaRuntime="${JDK%-ea}" -PtestkitGradleVersion="$TESTKIT_GRADLE" ${{ matrix.gradle_args }} - -Porg.gradle.java.installations.paths="$TEST_JDK" + -Porg.gradle.java.installations.paths="$TEST_JDK" -PtestkitDir="$GRADLE_USER_HOME/test-kit" - name: Publish Test Report uses: mikepenz/action-junit-report@a16be3a69023e9bd7e748ede768b3282ea7b30ce # v6.7.1 @@ -210,6 +222,10 @@ jobs: - name: Cache Gradle's downloads uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 with: + gradle-home-cache-includes: | + caches + notifications + test-kit/caches/modules-2 gradle-home-cache-excludes: | caches/build-cache-1 caches/modules-2/files-2.1/com.jetbrains.intellij.idea @@ -258,7 +274,9 @@ jobs: out-dir: ${{ runner.temp }}/deb-package - name: Test the plugins against the image - run: ./gradlew -PnativeImage=true :open-java-format-jdk-bootstrap:test :gradle-open-java-format:test + run: >- + ./gradlew -PnativeImage=true -PtestkitDir="$GRADLE_USER_HOME/test-kit" + :open-java-format-jdk-bootstrap:test :gradle-open-java-format:test env: JDK21_HOME: ${{ steps.jdk21.outputs.path }} @@ -325,6 +343,10 @@ jobs: - name: Cache Gradle's downloads uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 with: + gradle-home-cache-includes: | + caches + notifications + test-kit/caches/modules-2 gradle-home-cache-excludes: | caches/build-cache-1 caches/modules-2/files-2.1/com.jetbrains.intellij.idea diff --git a/gradle-open-java-format/build.gradle b/gradle-open-java-format/build.gradle index 73a7cd278..45453015b 100644 --- a/gradle-open-java-format/build.gradle +++ b/gradle-open-java-format/build.gradle @@ -179,6 +179,15 @@ tasks.named("test").configure { systemProperty 'testkit.gradleVersion', testkitGradleVersion.get() } + // The Gradle user home of the TestKit builds, which their downloads go to: the Android Gradle plugin and its + // dependencies above all. TestKit's default is under this task's temporary directory, which CI's cache does not + // reach, so CI passes a directory in the Gradle user home it caches. Locally the default stays: one directory for + // every checkout would be shared by tests that delete from it. + def testkitDir = providers.gradleProperty('testkitDir').filter { !it.isEmpty() } + if (testkitDir.isPresent()) { + systemProperty 'org.gradle.testkit.dir', testkitDir.get() + } + if (rootProject.ext.nativeImageRequested) { dependsOn(writeNativeImagePath) } else { diff --git a/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/MultiProjectTest.java b/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/MultiProjectTest.java index f53e1ff96..ae6661603 100644 --- a/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/MultiProjectTest.java +++ b/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/MultiProjectTest.java @@ -112,12 +112,21 @@ void spotlessApply_formats_the_root_project_and_every_subproject_when_the_root_h void formats_with_a_formatter_dependency_that_has_variants_when_the_root_has_no_java() { writeLibraryWithVariants(); // idea: updateOpenJavaFormatXml runs with every build and resolves palantirJavaFormat in the root project. + // The library is looked for in its own repository only: without exclusiveContent the root project asked + // Maven Central for it first, and a 429 from Maven Central failed the test. var project = project() .plugins("idea") .buildGradle(""" allprojects { repositories { - maven { url = file("%s") } + exclusiveContent { + forRepository { + maven { url = file("%s") } + } + filter { + includeGroup 'test' + } + } } } dependencies {