Distributed Multi-Job Builds

How to use the distributed worker/aggregator mode to cache builds that run as multiple parallel jobs.

Why distributed mode exists

When multiple build jobs run in parallel and each publishes an independent full-cache generation, those generations diverge. Restoring only the newest one loses dependency downloads and other cache changes that exist solely in the other workers’ generations.

Distributed mode solves this with delta exchange:

  • Each worker job uploads assumed changed files and path-only activity observations for aggregate partitions, plus complete snapshots for any single-writer partitions it owns. It does not write the base cache directly.
  • An aggregator job, which waits for all workers to complete, downloads every delta, merges them, and saves the merged result as the new base cache entry.

Observed parallel changes in aggregate partitions are combined. Single-writer partitions use only their designated writer’s complete snapshot. On the next run, all workers start from a cache that reflects the combined output of every job from the previous run.

sequenceDiagram
    participant BC as Base cache
    participant WA as Worker A
    participant WB as Worker B
    participant AG as Aggregator

    BC-->>WA: restore
    BC-->>WB: restore
    WA->>WA: build + compute delta
    WB->>WB: build + compute delta
    WA-->>AG: upload Δ-A artifact
    WB-->>AG: upload Δ-B artifact
    AG->>AG: download Δ-A + Δ-B
    AG->>AG: merge deltas
    AG->>BC: save merged cache entry

On pull-request events, read-only mode performs no exchange: workers upload nothing, and an aggregator returns skipped-read-only. The examples skip the aggregator on those events. For the worker and aggregator lifecycle, see the delta exchange protocol.

Gradle workflow example

Two workers build different modules, and the aggregator merges their contributions. worker-a also writes the dependency metadata; see Gradle metadata writer. The workflow is also available in the repository as examples/gradle-distributed.yml. Adapt the module tasks; for the action ref, see Pin a release.

 1name: Gradle distributed cache
 2on: [push, pull_request, workflow_dispatch]
 3
 4permissions:
 5  contents: read
 6
 7env:
 8  # Pass identical cache-partitions to every job; the writer names one worker.
 9  MAMMOTH_CACHE_PARTITIONS: '[{"id":"dependency-metadata","writer":"worker-a"}]'
10
11jobs:
12  worker-a:
13    runs-on: ubuntu-latest
14    steps:
15      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
16      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
17        with:
18          distribution: temurin
19          java-version: '21'
20      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
21        with:
22          job-mode: distributed-worker
23          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
24      - run: ./gradlew :module-a:build
25
26  worker-b:
27    runs-on: ubuntu-latest
28    steps:
29      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
30      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
31        with:
32          distribution: temurin
33          java-version: '21'
34      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
35        with:
36          job-mode: distributed-worker
37          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
38      - run: ./gradlew :module-b:build
39
40  aggregator:
41    # Every worker and any optional writer, so their uploads finish first.
42    needs: [worker-a, worker-b]
43    # always() also aggregates after worker failures; pull requests skip the read-only no-op.
44    if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
45    runs-on: ubuntu-latest
46    steps:
47      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
48      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
49        with:
50          job-mode: distributed-aggregator
51          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
52          # The same workers as in needs, by Mammoth producer name.
53          dependent-jobs: worker-a, worker-b
54          # Recommended: explains missing workers in the job summary.
55          github-needs: ${{ toJSON(needs) }}

Choosing an existing worker as the writer avoids an extra job. Because both workers are listed in dependent-jobs, both ordinary completion envelopes remain required. needs ensures their post actions finish before aggregate prepare performs artifact discovery.

The aggregator does not need actions/setup-java: Mammoth itself does not run Java, and the aggregator runs no build. Add a JDK only when the aggregator job also runs Gradle or Maven.

Maven workflow example

The Maven action uses the same worker and aggregator topology.

 1jobs:
 2  worker-a:
 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        with:
14          job-mode: distributed-worker
15      - run: mvn -pl module-a verify
16
17  worker-b:
18    runs-on: ubuntu-latest
19    permissions:
20      contents: read
21    steps:
22      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
23      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
24        with:
25          distribution: temurin
26          java-version: '21'
27      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
28        with:
29          job-mode: distributed-worker
30      - run: mvn -pl module-b verify
31
32  aggregator:
33    needs: [worker-a, worker-b]
34    if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
35    runs-on: ubuntu-latest
36    permissions:
37      contents: read
38    steps:
39      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
40      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/maven@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
41        with:
42          job-mode: distributed-aggregator
43          dependent-jobs: worker-a, worker-b
44          # Recommended: explains missing workers in the job summary.
45          github-needs: ${{ toJSON(needs) }}

Aggregator checklist

Every distributed workflow sets the same four things on the aggregator. The examples on this page comment each of them.

  • needs lists every worker and any optional metadata writer, so their uploads finish before the aggregator looks for artifacts.
  • if: ${{ always() && ... }} lets the aggregator merge valid contributions after worker failures. The event conditions skip pull requests, where an aggregator is a read-only no-op.
  • dependent-jobs lists the same workers by their Mammoth producer names: the job ID, or the name of each matrix cell that runs Mammoth. Leave out a metadata writer that may be skipped.
  • github-needs: ${{ toJSON(needs) }} is recommended. It lets the summary say whether a missing worker was skipped, failed or uploaded nothing, and flags listed jobs outside needs.
  • Every job passes identical cache-partitions and cache-family inputs such as cache-key-prefix.

When contributions still go missing, compare the job summaries of the workers and the aggregator.

Matrix jobs

Every cell of a matrix job runs with the same workflow job ID. Mammoth therefore names each cell <job ID>-<matrix values>, with the values in alphabetical order of their matrix keys, lowercased, and with other characters than letters, digits and . replaced by -. A matrix job build with java-version: ['21', '25'] produces build-21 and build-25. Structured values and names longer than 100 characters use a 12-character hash instead of the values. A job with a single cell keeps its job ID.

Every key of the cell’s matrix counts, including keys added by include. A value computed from an expression, such as an operating system chosen by a workflow input, changes the name when the expression’s result changes. When the derived names are hashes or depend on such values, set github-job-name from the values that identify the cell instead.

List the name of every cell that runs Mammoth in the aggregator’s dependent-jobs, and use one of them as the metadata writer. Leave out cells that skip the Mammoth step, for example through a step condition on a matrix value: a listed cell that uploads nothing is reported as missing and prevents full sweep coverage. Keep the matrix job ID in the aggregator’s needs. An explicit github-job-name takes precedence; give each cell its own value if you set it. Cells that end up with the same name collide:

  • If two cells upload an identical artifact name, the second upload is rejected. That worker warns that its upload is unconfirmed, and its contribution is lost without failing the job.
  • If the names differ, the aggregator finds several artifacts for one producer in the same attempt and fails with Ambiguous raw worker artifacts.

The following workflow is also available in the repository as examples/gradle-distributed-matrix.yml.

 1name: Gradle distributed cache with a Java matrix
 2on: [push, pull_request, workflow_dispatch]
 3
 4permissions:
 5  contents: read
 6
 7env:
 8  # Pass identical cache-partitions to every job; the writer names one matrix cell.
 9  MAMMOTH_CACHE_PARTITIONS: '[{"id":"dependency-metadata","writer":"build-21"}]'
10
11jobs:
12  build:
13    runs-on: ubuntu-latest
14    strategy:
15      matrix:
16        java-version: ['21', '25']
17    steps:
18      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
19      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
20        with:
21          distribution: temurin
22          java-version: ${{ matrix.java-version }}
23      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
24        with:
25          # Each cell is named <job ID>-<matrix values>, here build-21 and build-25.
26          job-mode: distributed-worker
27          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
28      - run: ./gradlew build
29
30  aggregator:
31    # The matrix job ID covers all of its cells.
32    needs: [build]
33    # always() also aggregates after worker failures; pull requests skip the read-only no-op.
34    if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
35    runs-on: ubuntu-latest
36    steps:
37      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
38      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
39        with:
40          job-mode: distributed-aggregator
41          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
42          # Every cell's name, not the matrix job ID.
43          dependent-jobs: build-21, build-25
44          # Recommended: explains missing workers in the job summary.
45          github-needs: ${{ toJSON(needs) }}

Mammoth does not expand a matrix into its cells. When you add or remove a matrix value, update dependent-jobs too. A listed name without an envelope prevents full sweep coverage, or fails aggregation with allow-missing-dependent-jobs: false. A cell missing from the list is ignored for ordinary artifacts.

The metadata writer names one cell, not the whole matrix. Choose the cell whose dependency resolution is most representative, for example the one that runs the most tasks. The matrix cells share one cache family unless their cache-key-prefix differs; see sharing across Java versions, operating systems and architectures.

Using a config file

Repeat inputs can be moved to a shared config file. The file format is identical for both build tools — use the config keys matching your tool’s action.

1# .github/buildish-mammoth-gradle.yml  (Gradle example)
2cache-key-prefix: my-project-gradle-
3wrapper-properties-files: gradle/wrapper/gradle-wrapper.properties
4cache-partitions:
5  - id: dependency-metadata
6    writer: worker-a
 1# Each worker job
 2- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
 3  with:
 4    job-mode: distributed-worker
 5    config-file: .github/buildish-mammoth-gradle.yml
 6
 7# Aggregator job
 8- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
 9  with:
10    job-mode: distributed-aggregator
11    dependent-jobs: worker-a, worker-b
12    config-file: .github/buildish-mammoth-gradle.yml
13    github-needs: ${{ toJSON(needs) }}

Gradle metadata writer

Gradle’s dependency-metadata partition is enabled by default and uses single-writer publication. Choose one existing worker as its metadata writer and pass the same partition configuration to every worker and the aggregator. The writer is identified by Mammoth’s producer job identity: the workflow job ID, a matrix cell’s derived name (see Matrix jobs), or an explicit github-job-name. Use that exact identity for writer and dependent-jobs. A writer designates one producer, not the entire matrix.

Only that job’s complete configured metadata set replaces the previous snapshot. Other workers' artifact downloads still aggregate normally; their local dependency-metadata updates do not. Choose a writer whose build resolves the dependencies you want covered. Metadata learned only by other jobs may need resolution again later. A validated snapshot qualifies even if its build failed.

An aggregator owns the complete snapshot when no writer is configured or when it names itself. In either case its own post-build metadata wins. If another job is named, that job’s snapshot or the prepared fallback remains authoritative despite the aggregator’s local changes.

Optional metadata writer that can be skipped

A writer reference is optional snapshot discovery. To permit a metadata-only job to be skipped, include it in needs for ordering, but omit it from dependent-jobs. The ordinary build worker remains required. This example is available as examples/gradle-optional-metadata-writer.yml. It runs a second build to populate the writer’s metadata; use an existing suitable worker when that extra work is unnecessary.

 1name: Gradle cache with optional metadata writer
 2on:
 3  push:
 4  pull_request:
 5  workflow_dispatch:
 6    inputs:
 7      run_metadata:
 8        description: Run the metadata writer
 9        type: boolean
10        default: true
11
12permissions:
13  contents: read
14
15env:
16  # Pass identical cache-partitions to every job; the writer names the metadata job.
17  MAMMOTH_CACHE_PARTITIONS: '[{"id":"dependency-metadata","writer":"metadata"}]'
18
19jobs:
20  build:
21    runs-on: ubuntu-latest
22    steps:
23      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
24      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
25        with:
26          distribution: temurin
27          java-version: '21'
28      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
29        with:
30          job-mode: distributed-worker
31          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
32      - run: ./gradlew build
33
34  metadata:
35    if: ${{ github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && (github.event_name != 'workflow_dispatch' || inputs.run_metadata) }}
36    runs-on: ubuntu-latest
37    steps:
38      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
39      - uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
40        with:
41          distribution: temurin
42          java-version: '21'
43      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
44        with:
45          job-mode: distributed-worker
46          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
47      - run: ./gradlew build
48
49  optional-aggregator:
50    # Includes the optional writer, so its upload finishes first.
51    needs: [build, metadata]
52    # always() also aggregates after worker failures; pull requests skip the read-only no-op.
53    if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }}
54    runs-on: ubuntu-latest
55    steps:
56      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
57      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
58        with:
59          job-mode: distributed-aggregator
60          cache-partitions: ${{ env.MAMMOTH_CACHE_PARTITIONS }}
61          # Required workers only; omitting the writer lets it be skipped.
62          dependent-jobs: build
63          # Recommended: explains missing workers in the job summary.
64          github-needs: ${{ toJSON(needs) }}

On a manual run with run_metadata: false, the aggregator still runs and imports the required build envelope. The missing metadata contribution leaves the previous snapshot unchanged and produces a warning and GitHub summary entry. If no previous snapshot exists, metadata remains absent. If the metadata job does run, only its metadata snapshot is imported; its ordinary artifact updates are ignored because it is not in dependent-jobs.

If that job is also required for ordinary cached files, list it in dependent-jobs. Skipping it then keeps the previous snapshot as above and prevents full sweep coverage for that run; with allow-missing-dependent-jobs: false it fails aggregation instead. A malformed, ambiguous, corrupt, or incompatible writer contribution fails validation rather than silently falling back. An explicit empty snapshot is valid and clears the configured partition; it differs from an absent snapshot.

Defaults and operational behavior

With no writer configured, a writable aggregator publishes its own snapshot. Without its own build, that snapshot keeps the previous metadata and never picks up workers’ updates. The aggregator warns and names the setting in the GitHub summary. Configure the same writer everywhere: writer and publication policy are part of the partition’s compatibility key, so changing them starts that partition cold while other partitions keep restoring. Existing cache families are cold misses after this protocol update too.

The metadata partition must start without managed files. A miss leaves it empty at restore time. Excluded files remain. Explicit include/exclude overrides are allowed, and their effect on Gradle’s internal metadata relationships is the user’s responsibility.

Authoritative snapshot bytes may be held independently of a job’s mutable Gradle data. An assigned writer uploads its complete managed snapshot. Standalone jobs normally publish their own observed snapshot. Snapshot partitions skip Mammoth’s per-file GC. Artifact GC continues independently, so metadata can refer to evicted artifacts and offline completeness is not guaranteed. See Cache partitions and Gradle cache internals.

Requirements and constraints

Upgrade all workers, snapshot writers, aggregators and cache readers together when changing incompatible Action versions. Such releases either start a new cache family, so older base objects produce cold misses, or reject worker artifacts from other versions. The changelog names them. Start each worker and aggregator with an empty managed cache area and run Mammoth before other restores or build-tool invocations. Keep the roots exclusive through prepare, build and post. Read-only jobs restore base files under the same admission rules. See restore admission failures.

Job names must be unique within the workflow run. Delta artifacts are identified by job name. Two worker jobs with the same name would produce the same artifact name and the aggregator would only see one of them. Matrix cells get distinct names from their matrix values; see Matrix jobs.

Compare the job summaries when contributions go missing. Every job’s prepare summary shows its producer name, its cache family and who publishes each single-writer partition. A worker’s post summary repeats its producer name with the attempt it uploaded. The aggregator lists the workers it merged with their attempts and the listed jobs it found no artifact for. It warns when workers in its cache family uploaded artifacts that match no requested job. It also notes worker artifacts from other Mammoth cache families in the same run, which is expected when jobs use different cache-key-prefix values or build tools.

The aggregator must declare needs for every consumed worker and optional metadata writer. This ensures all deltas are uploaded before the aggregator starts and consumes them during prepare.

Choose whether aggregation should run after worker failures. Use if: always() together with trusted event/ref conditions when you want to consume valid envelopes from failed builds or report missing envelopes. A skipped worker or a missing post upload, including after cancellation, leaves its envelope absent. By default the aggregator warns, merges the available envelopes and does not count the run towards full sweep coverage. Set allow-missing-dependent-jobs: false to fail aggregation instead, for example to catch a misspelled job name or a missing needs entry early. Pull-request aggregators may be omitted entirely; if they do run, their read-only result is the explicit no-op described above.

Workers do not need the aggregator in their needs. Workers are independent of each other; only the aggregator depends on all workers.

Re-runs reuse retained worker envelopes. For each worker, the aggregator selects the highest available producer attempt that is not newer than its own attempt. A full rerun uses every new worker envelope; a failed-job rerun safely mixes rerun workers with retained earlier attempts; and an aggregator-only rerun reuses retained worker envelopes. Selection never crosses workflow run IDs.

Mammoth retains worker envelopes after failed and successful aggregation, including when no new cache generation is needed. Workers request seven days of artifact retention by default. Set worker-artifact-retention-days on either action to request a shorter period, for example one day to reduce artifact residence:

1- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
2  with:
3    job-mode: distributed-worker
4    worker-artifact-retention-days: 1

Shorter retention narrows the selective or aggregator-only retry window and can require rerunning expired workers. Base cache expiry and timestamp GC are independent. Retry availability ends when the backend expires or removes the artifacts, the workflow run is deleted, or a user or administrator removes them. Repository, organization, and backend limits can shorten the requested period; availability for the full period is not guaranteed. Retention uses temporary artifact storage until removal. Normal completion retires known operation-local staging. Failed or unconfirmed worker uploads can leave an immutable package at a reported path.

If a listed envelope is missing or expired, the aggregator warns with the worker name and merges the others; with allow-missing-dependent-jobs: false aggregation fails even if a base cache was restored. Rerun the affected worker and then the aggregator within the same workflow run. Use fresh dedicated roots for the affected invocations. Retained remote artifacts remain eligible for selection under the workflow/run and cache family rules. Mammoth does not resume local staging or attempt to salvage interrupted uploads.

A successful writable worker always uploads one envelope. This includes workers that changed no managed cache files: their explicit empty envelope is proof of participation and is distinct from a missing or failed worker.

Periodic GC

Workers and aggregators check dependency-gc-due during prepare. Each job discovers its own generation in the shared cache family. While GC is fresh, eligible workers can use OverlayFS or the Gradle read-only seed. Due writable jobs use the ordinary writable capture path to observe dependency access times. An aggregator may still publish ordinary changes when coverage is insufficient for a sweep.

The aggregator checks full coverage against its effective dependent-jobs list. Include every worker whose workload you expect to count, including conditional workers and the metadata writer where applicable. Each listed worker must provide usable sweep evidence from the current run and attempt for the exact generation the aggregator restored. If workers restore different generations, Mammoth warns and excludes the mismatched evidence from sweep coverage. A snapshot writer discovered outside the list can still supply usable activity. A subset passed to dependent-jobs is the subset the aggregator checks. An empty list cannot establish full coverage.

Coverage uses Mammoth job names: workflow job IDs, derived matrix cell names, or explicit github-job-name values. Use those exact names in dependent-jobs. Mammoth does not expand a matrix job ID into its cells or infer which cells ran. Matrix contributions count by their distinct producer names.

With the defaults, GC is due three days after the last completed sweep. An aggregator can sweep with incomplete coverage after one more day, provided it can still prepare and publish under the ordinary artifact rules. A job in dependent-jobs without an envelope prevents full coverage; it fails prepare only with allow-missing-dependent-jobs: false. A generation with no recorded sweep is due immediately, and forcing is immediately eligible when enabled. See dependency-gc-interval-days and dependency-gc-force-grace-days.

Access evidence is best effort. A Gradle or Maven build-cache hit can skip work that would have read a dependency. A worker can complete capture even if its build step was skipped. An old dependency can then be evicted and downloaded again on a later build.

A Gradle worker whose build failed, or started but recorded no result (for example a failure while resolving settings plugins), withholds its sweep evidence. Its cache changes are still published, but it does not count towards full coverage, so the sweep waits for a run in which every listed worker succeeds. A forced sweep after the grace period still proceeds without that worker’s usage. With forcing disabled, a worker that fails every run prevents sweeps. Maven workers have no build-result capture and count towards coverage regardless of the build outcome. To keep a deliberately failing Gradle build from withholding evidence, see expected child-build failures.

Use the due hint with conditional jobs

Workflows that already run their full worker set can keep their existing job graph. If you select workers using change detection, you can add an earlier job with job-mode: prepare-only. Use the same cache-family inputs and ref settings that the workers and aggregator use. This mode reads the generation record and emits dependency-gc-due. It skips restoring partitions and provisioning the build tool. Expose the step output as a job output and let an explicit 'true' run all worker jobs that contribute to the full set. Keep your existing gates for false and unknown, including any trusted event or ref conditions.

For example, add this job alongside an existing changes job and add the planner to each gated worker’s needs. This excerpt shows one worker gate. Keep each worker’s normal prepare, build, and post lifecycle.

 1jobs:
 2  cache-plan:
 3    runs-on: ubuntu-latest
 4    outputs:
 5      dependency-gc-due: ${{ steps.mammoth.outputs.dependency-gc-due }}
 6    steps:
 7      - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
 8      - uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
 9        id: mammoth
10        with:
11          job-mode: prepare-only
12          config-file: .github/buildish-mammoth-gradle.yml
13
14  worker-a:
15    needs: [changes, cache-plan]
16    if: ${{ needs.cache-plan.outputs.dependency-gc-due == 'true' || needs.changes.outputs.run-worker-a == 'true' }}
17    # Keep the existing runner and worker steps here.

Each job still performs its own lookup. The planner output is a scheduling hint. The aggregator checks the artifacts it actually admits before deciding whether to sweep. Pass the full producer list even when some workers are skipped. Skipped workers produce a warning and prevent a complete sweep for that run. A shortened list would also shorten the coverage requirement and let a sweep evict entries that only the omitted workers use.

Sharing across Java versions, operating systems and architectures

Gradle and Maven workers can share with an aggregator using another Java version, OS or architecture when their family inputs match. Every job summary shows the producer’s runner platform, so compare them to see whether a family mixes platforms. Same-path different contents still conflict under strict policies, including inconsistent Maven directories. Equal ordinary worker files can coalesce across permission differences. Native base permissions depend on the restoring host and SDK. Windows cannot reconstruct Unix execute bits that were lost, which matters for executables in cached task outputs.

Dependency artifacts and metadata, Gradle’s JAR and resource stores, compiled build scripts and wrapper distributions do not depend on the platform. Two cases do, and both come from build logic rather than from Mammoth:

  • Gradle build-cache entries of tasks whose outputs depend on the OS, architecture or JDK without declaring it as a task input. A shared Gradle remote build cache has the same exposure.
  • Artifact transforms that produce platform-specific output, for example by unpacking the current host’s native libraries, without a platform parameter.

Use a workflow input such as cache-key-prefix: project-${{ runner.os }}-${{ runner.arch }}- to isolate platforms, or include ${{ matrix.java }} for explicit Java separation. All jobs in a sharing group must resolve the same prefix. Maven platform artifacts and environment-dependent local installs need distinct coordinates/classifiers or explicit namespace isolation.

Gradle dependency layer

The Gradle dependency layer is enabled by default. An eligible writable distributed worker can consume an invocation-owned read-only dependency seed while keeping misses in its writable user home. Eligible Linux workers try OverlayFS first while GC is fresh. Due runs use ordinary writable capture. Standalone jobs and aggregators publish to the same family, and the designated writer keeps authority over the complete dependency metadata snapshot.

Keep the same setting across cooperating jobs. To use the ordinary cache family, set dependency-cache-layer: false on every publisher and worker.

1- uses: buildish-tooling/buildish-mammoth-cache/actions/github/gradle@5c0dee59a9c967b022c674b2f442f181511c8df7 # v0.8.4
2  id: mammoth
3  with:
4    job-mode: distributed-worker
5    wrapper-properties-files: gradle/wrapper/gradle-wrapper.properties
6- run: ./gradlew build

Use a selected Gradle wrapper that supports the read-only dependency cache. Mammoth restores modules-2/files-2.1 and the restored modules-2/metadata-* directories into the seed. Gradle chooses its own metadata format and writes misses to the writable cache. The seed output reports that the layer is available. Offline builds still need usable metadata and artifacts for their dependencies.

Activation requires both restored dependency partitions in the supported layouts, writable worker mode, restore-cleanup-mode: none, and no selected single-writer partition owned by that worker. Missing partitions, unsupported layouts, jobs without a selected wrapper, read-only jobs, and other roles use the complete ordinary installation before any seed roots are detached.

The default exports GRADLE_RO_DEP_CACHE for subsequent steps and emits the same absolute path as steps.mammoth.outputs.gradle-ro-dep-cache. With export-layer-environment: false, set that variable yourself for every consumer. An existing nonempty value conflicts with eligible prepare. Keep all consumers inside the prepare/post lifetime; do not save the path for another job. Post settles registered Gradle processes, captures only writable state, then retires the owned seed. Once advertisement is attempted, even a failed or interrupted prepare retains the path until its owning post, covering later always() or continue-on-error consumers. Incomplete activation runs cleanup only and publishes no worker envelope. Uncertain ownership or quiescence retains reported diagnostic state rather than deleting a potentially live or replaced path.

Inherited dependency bytes still download and extract once into the seed. They avoid writable capture and worker-delta upload. New dependencies use the writable cache. Publisher sweeps apply to aggregate dependency partitions in this family. Metadata retains its complete snapshot and designated-writer semantics. Gradle workflows moving from the ordinary family start the layered family cold unless a previous opt-in has already populated it.