Configure Maven Build Cache

Last updated: September 21, 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

  1. First set up a BuildFetch Cache Project with Maven as the project type.
  2. Open the Project's Remote Cache Setup tab, copy the Remote Cache URL, and generate a Token.
  3. 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>
  1. Configure .mvn/maven-build-cache-config.xml with 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>
  1. 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>

Cache Access

Use a cache:readonly Token by default on developer and AI agent machines. Trusted environments like CI should use a cache:readwrite Token and explicitly enable uploads.

For Token management, rotation, and Open Source guidance, see Set up BuildFetch Cache Project.

Read-only

export BUILDFETCH_MAVEN_REMOTE_CACHE_TOKEN="<generated-readonly-token>"
mvn verify

Read-write

export BUILDFETCH_MAVEN_REMOTE_CACHE_TOKEN="<generated-readwrite-token>"
mvn verify -Dmaven.build.cache.remote.save.enabled=true

See Also