Skip to content
Latchkey

GitHub Actions Workflow for Cache Gradle Builds

Cache Gradle so CI builds reuse dependencies and outputs.

This workflow uses the official Gradle setup action, which manages the dependency and build cache for you.

The workflow

.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: temurin, java-version: '21' }
      - uses: gradle/actions/setup-gradle@v4
      - run: ./gradlew build

Notes

  • gradle/actions/setup-gradle handles caching automatically.
  • Cache is only written from the default branch to avoid PR pollution.
  • Use the wrapper (./gradlew) for reproducible Gradle versions.

Run it cheaper

Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →