Skip to content

ci(mobile): cache Gradle so the APK build stops re-downloading Maven Central - #32

Merged
mattbalza merged 2 commits into
mainfrom
ci/mobile-gradle-cache
Aug 7, 2026
Merged

ci(mobile): cache Gradle so the APK build stops re-downloading Maven Central#32
mattbalza merged 2 commits into
mainfrom
ci/mobile-gradle-cache

Conversation

@mattbalza

Copy link
Copy Markdown
Owner

What broke

CI / Mobile failed on main (run 31196146152, 4m27s). Not a code failure:

Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/
kotlin-gradle-plugins-bom/1.9.20/kotlin-gradle-plugins-bom-1.9.20.pom'.
Received status code 429 from server: Too Many Requests

It died in mobile/android/settings.gradle.kts:20 resolving the dev.flutter.flutter-plugin-loader:1.0.0 plugin — i.e. at Gradle configuration time, before any of our code compiles.

Why it was reachable at all

The mobile: job caches Hermit (~/.cache/hermit/pkg) and pub (~/.pub-cache) but not Gradle. Every single run therefore re-resolved the whole Android/Kotlin dependency graph over the network from Maven Central.

Flutter's own retry is no help here: the log reads Retrying Gradle Build: #1, wait time: 100ms. Both attempts landed inside the same rate-limit window, 6 seconds apart.

The fix

Cache ~/.gradle/caches and ~/.gradle/wrapper, keyed on the Android build files plus mobile/pubspec.lock (the plugin set drives the Android dependency graph), using the same actions/cache/restore + actions/cache/save + continue-on-error: true idiom the job already uses for Hermit and pub.

This removes the round trip rather than retrying it, and takes time off the build as a side effect.

Known ceiling, marked in a comment: a cold cache (first run after a key change) still makes the request and could still be 429'd. That's a much rarer window than every run; if it recurs, the next rung is a retry with real backoff.

Test plan

  • Mobile passes on this PR — that run populates the cache (cold key).
  • A second run on the same key logs Cache restored from key: gradle-Linux-… and the APK build performs no Maven Central downloads.
  • YAML parses (yaml.safe_load), job goes 12 → 16 steps.

Note on urgency

The immediate red is already superseded — main head 6d87a168 is green (37 check-runs, 0 failed). This is the durable fix, not an unblock. Frequency was 1 failure in 11 recent Mobile runs.

…Central

The Mobile job caches Hermit and pub but not Gradle, so every run re-resolved
the entire Android/Kotlin dependency graph over the network. Run 31196146152
got a 429 from repo.maven.apache.org resolving kotlin-gradle-plugins-bom while
evaluating mobile/android/settings.gradle.kts, and Flutter's built-in retry
waits 100ms — both attempts died inside the same rate-limit window, 6s apart.

Caching ~/.gradle/caches and ~/.gradle/wrapper removes the round trip entirely
on a warm key rather than retrying it, and shortens the build besides.
The first version cached all of ~/.gradle/caches, which came out at 2429 MB.
The repo shares a 10 GB Actions cache budget with the cargo, pnpm and Hermit
entries, and LRU eviction would have pushed those out to keep this one.

modules-2 holds the downloaded artifacts — the network dependency that got
429'd. Everything else under caches/ is derived (build-cache, transforms, jars):
losing it costs CPU to recompute, which is not what was failing.
@mattbalza
mattbalza merged commit 1b5f47c into main Aug 7, 2026
24 checks passed
@mattbalza
mattbalza deleted the ci/mobile-gradle-cache branch August 7, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant