You are reading documentation for 0.4.0. The latest release in the 0.4 line is 0.4.2.

The latest stable release is 0.8.4.

Maven Caching Patterns

How to get the most out of Maven caching — what is portable in the local repository, why certain files are excluded, and how to structure workflows for maximum cache effectiveness.

What gets cached

The Maven action caches the local repository (~/.m2/repository by default, covered by the repository partition) and, when the Maven Wrapper is in use, the wrapper distribution downloads (~/.m2/wrapper/dists, covered by the wrapper-dists partition).

Repository paths encode coordinates, not content hashes. Releases from different repositories, snapshots, and locally installed builds can have different bytes at the same path. Mammoth preserves _remote.repositories so Maven Resolver can distinguish downloaded content from local installs and apply its normal origin checks. Keep repository IDs, mirror mappings, and Resolver configuration compatible across jobs sharing a cache. A changed origin can require downloads or fail offline; markers do not authenticate content or compensate for Resolver’s same-ID URL fallback.

Use a dedicated Maven user home and cold-seed it from a fresh repository when upgrading from the marker-excluding policy. The changed partition fingerprint starts a new cache family automatically; old generations and worker packages are not restored through a fallback.

Snapshots and local build outputs

Both remain included by default. Resolver controls snapshot updates; cached bytes do not guarantee freshness. mvn install outputs remain local installs after restore and can satisfy resolution independently of the active remotes. Exclude complete coordinate directories when those outputs should be rebuilt, using the existing partition input:

 1cache-partitions: |
 2  [
 3    {
 4      "id": "repository",
 5      "includes": ["repository/**"],
 6      "excludes": [
 7        "repository/**/*-SNAPSHOT/**",
 8        "repository/com/example/my-project/**"
 9      ]
10    }
11  ]

The group/artifact exclusion is an example for the project’s own installed outputs. Adjust it to your coordinates. Keep origin markers with managed artifacts so Resolver can apply its existing origin checks. Exclude whole directories to leave artifact bytes and their markers outside sharing.

During installation, Mammoth validates incoming views against protected non-transient siblings. GC keeps a complete coordinate when an excluded artifact would survive. Default resolver check-state and lock exclusions continue to apply.

Default timestamp garbage collection

Maven local repositories tend to grow monotonically because old dependency versions remain valid even after the project stops using them. The action therefore enables cache-gc-mode: timestamp by default for both Maven and Gradle.

Eligible writable Maven posts prune managed repository directories older than cache-gc-older-than-days (14 by default) when current activity does not protect them. A directory is retained if any managed sibling survives, so old marker timestamps cannot remove origin evidence while artifact bytes remain. Current path-only usage also protects siblings. No historical last-use grace is stored; noatime/relatime and clocks can hide activity. This keeps GitHub Actions cache entries from growing indefinitely while still allowing Maven to redownload an old artifact if the build needs it again.

If a workflow intentionally relies on a large offline-style local repository, either increase the cutoff or disable GC:

1cache-gc-older-than-days: '30'
2# or:
3cache-gc-mode: off

Why certain files are always excluded

Three patterns are hard-excluded from every Maven partition:

  • **/*.lastUpdated: artifact resolution failure/check state that can suppress retries.
  • **/resolver-status.properties: metadata update-check timestamps and errors that can suppress fresh checks after restore.
  • **/*.lock: transient synchronization state recreated by the consuming job.

The first two discard check history, not artifact provenance. Maven metadata XML and _remote.repositories remain cached. Resolver’s update policy still applies; these exclusions do not force every artifact or snapshot to be downloaded again. See Maven cache internals for the tested behavior.

Maximizing cache hit rates

Commit your POM files and nothing else

The cache key includes a fingerprint of the active partition layout. The content of your POMs does not factor into the key. This means:

  • Dependency updates do not by themselves change the partition fingerprint.
  • Warming the cache is fastest when the first run resolves all dependencies end-to-end.
  • Running mvn dependency:go-offline as a dedicated pre-build step is not needed and slows down the first run unnecessarily — let the build resolve naturally and the action will cache whatever lands in the local repository.

Use the lifecycle your build requires

Use mvn verify for verification or mvn install when subsequent builds need locally installed outputs. Downloaded dependencies are cached as Maven resolves them during either lifecycle. Local installation is a separate operation; use the exclusions above when those outputs should not be shared.

Multi-module projects and parallel goals

For multi-module projects, finalize observes activity across the managed local repository after the build completes. You do not need to structure goal invocations specially — just ensure the final invocation runs all modules (mvn -T 1C verify or similar) so every module’s output reaches the local repository before the finalize step runs.

In distributed mode, each changed managed file under repository/ carries its immediate managed directory as upserts, keeping artifacts and origin markers in the worker’s complete view. Use a common seeded repository and one writer per changed directory under the default policy. The qualified topology uses Resolver’s enhanced local repository manager, default _remote.repositories tracking filename, and unsplit repository/ layout. Different artifact/version directories can be populated in parallel. Use a standalone build to publish common plugins and transitive dependencies in a Mammoth generation. Workers can then restore that generation into initially empty managed areas before resolving their disjoint dependencies.

Under the default policy, different worker views of the same directory fail aggregation, including disjoint classifiers or local installs sharing a marker. Even equal marker entries can differ in timestamp comments and fail the byte comparison. The duplicate-path override cannot bypass this check. An aggregator also rejects updates missing non-transient siblings already present in its repository, including excluded artifact files. Serialize overlapping resolution or use standalone mode rather than removing markers. Worker envelopes remain available for retries; rerun from a fresh aggregator after a partial filesystem failure.

Structuring staged workflows

Some projects run goals in stages — for example, build and test in parallel, then deploy separately. A typical pattern:

 1jobs:
 2  build-and-test:
 3    runs-on: ubuntu-latest
 4    permissions:
 5      contents: read
 6    steps:
 7      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
 8      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
 9        with:
10          distribution: temurin
11          java-version: '21'
12      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@<commit-sha>
13      - run: mvn verify
14
15  deploy:
16    needs: build-and-test
17    runs-on: ubuntu-latest
18    permissions:
19      contents: read
20    steps:
21      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
22      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
23        with:
24          distribution: temurin
25          java-version: '21'
26      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@<commit-sha>
27        with:
28          read-only: true
29      - run: mvn deploy -DskipTests

The deploy job uses read-only: true so it benefits from the warm cache populated by build-and-test without writing a competing cache entry.

Goal-level incremental caching

Maven does not have a built-in equivalent to Gradle’s task-output caching. Plugin-based extensions exist that add goal-level incremental caching to Maven, analogous to Gradle’s build cache. These operate independently of this action and require separate configuration. This action is compatible with such extensions — the files they produce in the local repository are captured and cached alongside regular dependency artifacts.

Selecting one worker directory on conflict

For independent cold workers, an explicit partition policy can select one complete worker directory instead of rejecting differing marker bytes:

1cache-partitions:
2  - id: repository
3    conflict-handling: choose-worker-directory

Use the same configuration in producers and aggregators. The smallest producer job name in JavaScript UTF-16 ordinal order wins each immediate directory after discovery selects eligible attempts. It keeps that worker’s artifacts, marker and attributes together, without parsing Java properties. Different file sets also trigger selection. Other workers’ classifiers, local installs and origin entries can be lost; offline resolution is not guaranteed for losing workers. A discarded local install may not be downloadable anywhere.

This policy is optional and creates a separate cache family. Common seeding remains supported with the strict default. Existing target siblings absent from the winner, including excluded artifacts, still prevent application; selection does not delete files. See configuration for constraints, forwarding behavior and interaction with the generic duplicate override.