Skip to content
Latchkey

How to Cache Gradle and CocoaPods in CI

Cache ~/.gradle/caches keyed on Gradle files and the Pods directory keyed on Podfile.lock to cut cold-build time.

Use actions/cache with keys derived from *.gradle* and Podfile.lock. A stable key means unchanged dependencies restore instantly instead of downloading again.

Steps

  • Cache ~/.gradle/caches and ~/.gradle/wrapper keyed on Gradle files.
  • Cache the ios/Pods directory keyed on Podfile.lock.
  • Add restore-keys so a near-miss still gives a partial hit.

Workflow

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: |
      ~/.gradle/caches
      ~/.gradle/wrapper
    key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
    restore-keys: gradle-
- uses: actions/cache@v4
  with:
    path: ios/Pods
    key: pods-${{ hashFiles('ios/Podfile.lock') }}
    restore-keys: pods-

Gotchas

  • Cache the resolved Pods, but still run pod install so the workspace references are correct.
  • Do not cache build outputs you need fresh; cache only the dependency stores.

Related guides

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