Enable or disable the Maven build cache extension: the switches that work
The Apache Maven Build Cache Extension has command-line switches to turn it off, skip the lookup, stop talking to the server, or stop uploading. Here is what each one did in a real run against a self-hosted cache (FosterStack Cache 0.2.1, Maven 3.10.0, extension 1.2.3).
The short answer
-Dmaven.build.cache.enabled=falseturns the cache off for that build.-Dmaven.build.cache.skipCache=trueignores stored results and builds fully.-Dmaven.build.cache.remote.enabled=falsestops all contact with the server.-Dmaven.build.cache.remote.save.enabled=falselets the build download but never upload.
What we ran
A small Maven project with the extension set up as described in Maven remote build cache setup. Every build used a fresh copy of the project and an empty local build cache, so the only shared thing was the server. All seven builds ended with BUILD SUCCESS.
| Build | Added to the command | Result |
|---|---|---|
| 1 | nothing (empty server) | Compiled, and saved the result to the server |
| 2 | nothing (another machine) | Restored from the cache, no compile |
| 3 | -Dmaven.build.cache.enabled=false | Compiled. The cache was off |
| 4 | -Dmaven.build.cache.skipCache=true | Compiled, although a result was stored |
| 5 | -Dmaven.build.cache.remote.enabled=false | Compiled. It did not ask the server at all |
| 6 | -Dmaven.build.cache.remote.save.enabled=false (empty server) | Compiled. The server still had 0 entries |
| 7 | same as 6, again | Compiled again, because nothing was ever stored |
What Maven prints for each switch
enabled=false:
[INFO] Cache disabled by command line flag, project will be built fully and not cached
skipCache=true:
[INFO] Project demo:demo is marked as requiring force rebuild, will skip lookup in build cache
With remote.enabled=false there was no download attempt in the log. With remote.save.enabled=false the build still looked in the server, found nothing, and built locally.
"Error downloading cache item" on a normal miss
The first build against an empty server printed this line, and it still succeeded:
[ERROR] Error downloading cache item: http://127.0.0.1:18160//v1.1/demo/demo/ebb9bceba2f7a6bc/buildinfo.xml
[INFO] Remote cache is incomplete or missing, trying local build for demo:demo
In our run this was an ordinary miss: nothing was stored under that key yet, so Maven built the project itself. The next line says so. If you see this line on a cache that you know holds the result, check the address, the login and the proxy: see Maven build cache not restoring.
Which one to use
- A suspect build:
enabled=falserules the cache out completely. - Make sure you build fresh:
skipCache=true, for example for a release build. - Working offline or off the VPN:
remote.enabled=false, so Maven does not wait on a server it cannot reach. - Developers read, CI writes:
remote.save.enabled=falseon developer machines. The same idea for Gradle is on CI writes, developers read. A read-only login on the server enforces it.
The same job for Gradle is on enable or disable the Gradle build cache.
Run on Maven 3.10.0 with maven-build-cache-extension 1.2.3 and FosterStack Cache 0.2.1, macOS (arm64).