Getting Started

What this action does, how to add it to a workflow, and how it works under the hood.

Gradle dependency metadata is cached by default in dependency-metadata. A standalone job owns its complete snapshot automatically. On a cache miss, that partition starts empty. For distributed jobs, select a metadata writer using the same partition configuration in every job. Without a configured writer, the aggregator publishes its own complete snapshot; ordinary workers’ metadata updates are omitted.

What this action does

This action speeds up JVM builds on CI by caching the build tool’s local artifact store between runs. On each run it:

  1. Restores the cache before the build so the build tool finds its dependencies already in place.
  2. Publishes a new complete immutable cache generation after a material change. Unchanged hits do not create duplicate entries.

Two job modes are available for both build tools:

  • Single-job — one build job per workflow run. The action wraps that job and handles everything automatically.
  • Distributed multi-job — multiple parallel build jobs. Each job uploads only the delta it produced; a dedicated aggregator job merges all deltas into the next cache entry so no job’s work is lost.

Gradle

For Gradle the action caches GRADLE_USER_HOME and additionally:

  • Provisions any missing gradle-wrapper.jar files, verifying each one with a SHA-256 checksum and a PGP signature before writing it to disk. See Security for details.

Maven

For Maven the action caches the Maven user home (~/.m2 by default, or the path set by maven-user-home), including the local repository under repository/ and Maven Wrapper downloads under wrapper/dists/. No wrapper provisioning is performed — Maven’s own bootstrap is handled by the runner environment or actions/setup-java.

Build-output caching requires a separately configured Maven extension. See goal-level incremental caching for how it relates to Mammoth’s repository caching.

Workflow shape

For an existing workflow, first use Adoption and Migration to choose cache owners, preserve write restrictions and define a small pilot.

Place the action step before the first Gradle or Maven invocation and before any step that populates the managed cache area.

Pin a release

In released docs, the examples pin their release: the full commit SHA that its tag points to, followed by the version as a comment. Development docs describe unreleased changes, so they show <release-sha> instead. Replace it with the full commit SHA that a release tag points to, and keep the version in a comment:

1- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@<release-sha> # vX.Y.Z

The example workflows under examples/ in the repository always use <release-sha>.

Releases and candidates are listed on GitHub Releases. To get the commit SHA of a tag, run:

1git ls-remote https://github.com/buildish-tooling/buildish-mammoth-cache 'refs/tags/vX.Y.Z^{}'

Only release and candidate tags point to commits that contain the generated dist/ bundles the action runs. Commits on main, including the “Source commit” named in the release notes, do not, and fail as action refs. The tags are annotated, so use the ^{} line above, not the tag object’s own SHA. Dependabot and Renovate can keep the SHA and the version comment up to date.

Leave dependency caching disabled in actions/setup-java and remove any other restore that populates the same cache area. JDK installation and settings-only setup can run before Mammoth when they leave the enabled partitions empty. Existing directories and settings outside those partitions are allowed. Mammoth rejects existing managed files and preserves them. See restore admission failures for dedicated-home examples.

Cache and same-run delta artifact operations use job-scoped Actions runtime credentials, so they do not require actions: write. The examples grant only contents: read for checkout. See Security for the full permissions boundary.

The action defaults to read-only on pull_request and pull_request_target events, so cache writes from untrusted forks are automatically suppressed. Repository config can make this policy stricter but cannot lower the pull-request floor; only a direct workflow input can do that. Read-only jobs still restore base files and must meet the same prepare preconditions. Read-only workers upload nothing, and read-only aggregators skip artifact exchange.

Gradle

 1jobs:
 2  build:
 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/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
13      - run: ./gradlew build

Maven

 1jobs:
 2  build:
 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@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
13      - run: mvn verify

How it works

The action runs twice per job: a prepare step before the build and a finalize step after. Prepare records a cutoff after restore; finalize observes metadata after the build. Workers exchange assumed changed files and usage paths; eligible writers save complete generations when required. Filesystem and clock behavior make activity detection best-effort.

sequenceDiagram
    participant P as prepare
    participant B as Your build steps
    participant F as finalize

    P->>P: restore cache
    note over P: Gradle only: provision gradle-wrapper.jar
    P->>P: record activity cutoff
    P-->>B: hand off
    B->>B: build runs …
    B-->>F: job post step
    F->>F: scan metadata before own reads
    F->>F: freeze upsert, used and GC decisions
    F->>F: publish complete generation if required

For distributed multi-job builds, worker jobs upload their delta as a workflow artifact instead of saving the cache directly. An aggregator job then merges all worker deltas into a single cache entry. See Distributed multi-job for details.