From 602271994f92e483f4f77b2cdc6638111790de26 Mon Sep 17 00:00:00 2001 From: Marcus Lagergren <1062473+lagergren@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:34:48 +0100 Subject: [PATCH] Keep the build cache between CI runs The local build cache lives in each checkout, to keep concurrent builds of several checkouts apart. CI builds one new checkout per job, so a run never reused anything an earlier run built: every run compiled and tested the whole XDK, about 6.5 of the 9 minutes of its main Gradle build. On CI the cache now stays in the Gradle user home, where setup-gradle saves it after master's runs and restores it for later runs, pull requests included, which only read it. Locally nothing changes. --- build-logic/aggregator/settings.gradle.kts | 5 ++++- build-logic/common-plugins/settings.gradle.kts | 5 ++++- build-logic/settings-plugins/settings.gradle.kts | 5 ++++- settings.gradle.kts | 7 ++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/build-logic/aggregator/settings.gradle.kts b/build-logic/aggregator/settings.gradle.kts index 06bfee11f2d..79b620d0d92 100644 --- a/build-logic/aggregator/settings.gradle.kts +++ b/build-logic/aggregator/settings.gradle.kts @@ -1,6 +1,9 @@ buildCache { local { - directory = file("../../.gradle/build-cache") + // As in the root build: each checkout keeps its own cache, and CI keeps it in the Gradle user home. + if (!providers.environmentVariable("CI").isPresent) { + directory = file("../../.gradle/build-cache") + } } } diff --git a/build-logic/common-plugins/settings.gradle.kts b/build-logic/common-plugins/settings.gradle.kts index 1fe7567ea13..20639aa33b0 100644 --- a/build-logic/common-plugins/settings.gradle.kts +++ b/build-logic/common-plugins/settings.gradle.kts @@ -1,6 +1,9 @@ buildCache { local { - directory = file("../../.gradle/build-cache") + // As in the root build: each checkout keeps its own cache, and CI keeps it in the Gradle user home. + if (!providers.environmentVariable("CI").isPresent) { + directory = file("../../.gradle/build-cache") + } } } diff --git a/build-logic/settings-plugins/settings.gradle.kts b/build-logic/settings-plugins/settings.gradle.kts index d561ab88d66..2d8fe195053 100644 --- a/build-logic/settings-plugins/settings.gradle.kts +++ b/build-logic/settings-plugins/settings.gradle.kts @@ -1,6 +1,9 @@ buildCache { local { - directory = file("../../.gradle/build-cache") + // As in the root build: each checkout keeps its own cache, and CI keeps it in the Gradle user home. + if (!providers.environmentVariable("CI").isPresent) { + directory = file("../../.gradle/build-cache") + } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index f135e29630b..67ec3043a70 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,7 +32,12 @@ buildCache { // of this repository build concurrently (e.g., ../research-fork and ../gradle94). // Without this, both projects share ~/.gradle/caches/build-cache-1/ and concurrent // writes can corrupt cached artifacts (ZipFile invalid LOC header errors). - directory = file(".gradle/build-cache") + // CI builds one checkout at a time and keeps the cache in the Gradle user home, which + // setup-gradle saves after master's runs and restores for later runs, so that a run + // reuses what an earlier one built. + if (!providers.environmentVariable("CI").isPresent) { + directory = file(".gradle/build-cache") + } } }