Configure Maven Build Cache
Last updated: September 2, 2026
What is Maven Build Cache
The Apache Maven Build Cache Extension adds build and test caching to Maven 3.9+ and Maven 4.
Maven Remote Cache shares cached build outputs across CI and developer machines, reducing repeated build and test work.
BuildFetch Cache natively implements Maven Build Cache HTTP protocol spec and acts as a fully compliant Maven Build Cache backend.
Configure Maven Build Cache
- First set up a BuildFetch Cache Project with Maven as the project type.
- Open the Project's Remote Cache Setup tab, copy the Remote Cache URL, and generate a Token.
- Add the Maven Build Cache extension to
.mvn/extensions.xml:
<extensions>
<extension>
<groupId>org.apache.maven.extensions</groupId>
<artifactId>maven-build-cache-extension</artifactId>
<version>1.3.0</version>
</extension>
</extensions>- Configure
.mvn/maven-build-cache-config.xmlwith the endpoint shown in the BuildFetch Project Cache Setup tab:
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.4.0 https://maven.apache.org/xsd/build-cache-config-1.4.0.xsd">
<configuration>
<enabled>true</enabled>
<remote enabled="true" id="buildfetch" transport="resolver">
<url>https://cache.region.buildfetch.com/project-id/maven/</url>
</remote>
</configuration>
</cache>- Put the BuildFetch token in
~/.m2/settings.xml, outside the repository:
<settings>
<servers>
<server>
<id>buildfetch</id>
<username>buildfetch</username>
<password>${env.BUILDFETCH_MAVEN_REMOTE_CACHE_TOKEN}</password>
</server>
</servers>
</settings>export BUILDFETCH_MAVEN_REMOTE_CACHE_TOKEN="<generated-token>"
# Populate the shared remote cache from trusted CI.
mvn verify -Dmaven.build.cache.remote.save.enabled=true
# Read from local + remote cache.
mvn verifyRemote writes are disabled by default. Generate a cache:readwrite Token for trusted CI jobs that populate the remote cache. For developer machines we recommend cache:readonly Tokens unless developers need to write shared entries.
For project-specific cache correctness and portability tuning, see Apache Maven's official Getting Started, Remote Cache setup, and Build Cache Parameters. Maven specifically recommends tracking critical runtime plugin parameters, such as Surefire skipTests, when they affect whether a cached result is reusable.
That's it, enjoy faster Maven builds!