Infrastructure worth keeping — and kept patched.

Enable or disable the Gradle build cache: flag, property or settings

Gradle uses the build cache only when it is switched on and a cache is set up. Here is every way we tried to switch it on and off, with what each one did against a real cache server (release 0.2.1, Gradle 9.8.0).

The short answer

What we ran

A four-module project with the cache address set in settings.gradle.kts (shown below). Each run used its own copy of the project and an empty Gradle home, so the only Gradle state shared was the cache server. An earlier set of runs started from a project folder that still held build output left over from an earlier test; we repeated all of them from a clean copy and got the same results. The table below shows the clean runs. We ran only :core:compileJava and looked at what Gradle printed next to it. Every build ended with BUILD SUCCESSFUL.

How it was switchedCommandResult
Flag (first build)gradle :core:compileJava --build-cacheRan, and saved the result to the server
Nothing setgradle :core:compileJavaRan. The cache was not used
Flaggradle :core:compileJava --build-cacheFROM-CACHE
Property in gradle.propertiesorg.gradle.caching=trueFROM-CACHE
Property, and the flag offorg.gradle.caching=true and --no-build-cacheRan. The flag won
System propertygradle :core:compileJava -Dorg.gradle.caching=trueFROM-CACHE
Flag, and rerun everything--build-cache --rerun-tasksRan, even though a result was stored

Which one to use

The address still has to be set

This is the settings.gradle.kts we ran. Replace the address with your server's. We used 127.0.0.1 over plain HTTP because the test ran on one machine; use HTTPS across a network.

buildCache {
    local { isEnabled = false }
    remote<HttpBuildCache> {
        url = uri("http://127.0.0.1:18141/")
        isPush = true
        isAllowInsecureProtocol = true
    }
}

Read-only: turn off uploading, not the cache

Setting isPush = false lets a build download from the cache but never upload. We tried it against an empty server with the cache switched on. The build succeeded and ran the task, and the server still held 0 entries afterwards. A second build also ran the task, because nothing had ever been stored. Read-only only helps when someone else, such as CI, fills the cache. That setup is described in CI writes, developers read.

If you do not see FROM-CACHE

Work through why the hit rate is low and remote cache not working. To clear stored results, see reset the build cache.

Run on Gradle 9.8.0 with FosterStack Cache 0.2.1, macOS (arm64), Java 27.