Skip to content

Add read-only mode for dependency caching #1168

Description

@brunoborges

Description:
Add a cache-read-only input for the built-in Maven, Gradle, and sbt dependency caches. When enabled, setup-java should restore matching caches normally but skip all cache saves in the post action, including independently managed wrapper caches.

Example:

- uses: actions/setup-java@v6
  with:
    distribution: temurin
    java-version: '21'
    cache: maven
    cache-read-only: ${{ github.ref != 'refs/heads/main' }}

The input should default to false to preserve existing behavior. Documentation should recommend read-only caching for pull requests, merge queues, short-lived branches, and fan-out matrix jobs, with one default-branch or seed job responsible for populating caches.

Acceptance criteria:

  • cache-read-only: true restores the main dependency cache and any wrapper caches.
  • The post action does not archive or upload any cache when read-only mode is enabled.
  • Existing behavior remains unchanged when the input is omitted or set to false.
  • Logs clearly state that saving was skipped because caching is read-only.
  • Unit and end-to-end tests cover Maven, Gradle, and sbt behavior.
  • The README documents a default-branch writer pattern and a matrix/seed-job pattern.

Justification:
Every successful cache-enabled job can currently attempt a cache write. In pull-request, merge-queue, and matrix workflows, this creates large duplicate archives that are often scoped to temporary refs or lose reservation races. These uploads increase post-job duration, billed runner time, network usage, and cache storage pressure; they can also evict broadly reusable default-branch caches.

A first-class restore-only mode lets customers retain fast dependency restores while centralizing cache writes in the jobs most likely to produce complete, reusable entries. This follows the caching strategy already supported by actions/cache/restore and recommended by gradle/actions/setup-gradle, while keeping setup-java caching simple for common workflows.

Are you willing to submit a PR?
Yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions