Skip to content
Latchkey

gradle/gradle-build-action "cache write not permitted" on fork PRs

On fork PRs GitHub issues a read-only token, so the Actions cache cannot be written. gradle-build-action detects this and disables cache writes, which is expected, not a bug.

What this error means

On a fork PR the Gradle step logs "Cache write is not permitted in this context" and saves nothing.

github-actions
Cache write is not permitted in this context.
Gradle User Home cache will be read-only.

Common causes

Read-only token on fork PRs

Fork-originated pull_request runs get a read-only token that cannot write cache entries.

Cache write intentionally disabled

The action disables writes to avoid cache poisoning from untrusted forks.

How to fix it

Accept read-only on forks; warm the cache on trusted branches

  1. Let fork PRs run read-only; treat the message as informational.
  2. Populate the cache from pushes to your default branch so PRs read a warm cache.
  3. Use a separate trusted workflow if writes on PRs are required.
.github/workflows/gradle.yml
on:
  push:
    branches: [main]
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: gradle/actions/setup-gradle@v4

How to prevent it

  • Warm caches on default-branch pushes so fork PRs benefit read-only.
  • Do not expect cache writes from untrusted fork PRs.

Frequently asked questions

What causes ""Cache write is not permitted in this context""?
Fork-originated pull_request runs get a read-only token that cannot write cache entries.
How do I fix "Cache write is not permitted in this context"?
Accept read-only on forks; warm the cache on trusted branches

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card