Infrastructure worth keeping — and kept patched.

Maven build cache extension in a multi-module project: a real run

With many modules, the Apache Maven Build Cache Extension keeps one stored result per module. We ran a three-module project against a self-hosted cache (FosterStack Cache 0.2.1, Maven 3.10.0, extension 1.2.3) and recorded which modules were restored and which were built.

The short answer

What we ran

Three modules: core has no dependencies, util uses core, and app uses util. Each has six small Java classes. Every build used a fresh copy of the project and an empty local build cache, so the only shared thing was the cache server. All six builds ended with BUILD SUCCESS.

Buildcoreutilapp
1. First build, as CI would do itbuiltbuiltbuilt
2. Another machine, same coderestoredrestoredrestored
3. Edit inside a method in corebuiltbuiltbuilt
4. A teammate makes the same editrestoredrestoredrestored
5. Edit only apprestoredrestoredbuilt
6. Edit only utilrestoredbuiltbuilt

"Restored" is the log line Found cached build, restoring demo:core from cache for that module. "Built" means Maven compiled it, then saved the result.

What this means for your project

Set it up once, in the parent

Two files in the .mvn folder at the root of the project, the same as for a single module:

<!-- .mvn/extensions.xml -->
<extensions>
  <extension>
    <groupId>org.apache.maven.extensions</groupId>
    <artifactId>maven-build-cache-extension</artifactId>
    <version>1.2.3</version>
  </extension>
</extensions>
<!-- .mvn/maven-build-cache-config.xml -->
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.2.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.2.0 https://maven.apache.org/xsd/build-cache-config-1.2.0.xsd">
  <configuration>
    <enabled>true</enabled>
    <remote enabled="true" saveToRemote="true" id="fosterstack-cache">
      <url>http://127.0.0.1:18180/</url>
    </remote>
  </configuration>
</cache>

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. For logins, see Maven remote build cache setup.

If modules are not restored

See Maven build cache not restoring. To turn the cache off or skip it for one build, see enable or disable the extension.

First run: Maven 3.10.0 with maven-build-cache-extension 1.2.3 and FosterStack Cache 0.2.1, macOS (arm64).

Second run: Linux, 0.2.2

The run above was on a Mac with 0.2.1. We ran the table again on a GitHub-hosted Linux machine with FosterStack Cache 0.2.2, Maven 3.10.0, extension 1.2.3 and Java 21, each build on a fresh copy of the project with an empty local build cache. All six rows matched the table, and every build ended with BUILD SUCCESS.

The run and its log are public.