{
  "id": 20134154,
  "title": "Cache Gradle GitHub Actions builds, and Maven, with numbers",
  "url": "https://urgent.news/2026/11/15/cache-gradle-github-actions-builds-and-maven-with-numbers",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-15T07:24:45.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/kalemi/cache-gradle-github-actions-builds-and-maven-with-numbers-4c73"
  },
  "original_language": "en",
  "account": "To optimize Gradle and Maven builds using GitHub Actions, two specific actions can be utilized: gradle/actions/setup-gradle and actions/setup-java. The gradle/actions/setup-gradle action caches the entire Gradle User Home, while actions/setup-java caches Maven's ~/.m2/repository directory.\n\nFor Maven, caching is straightforward as the directory only contains downloaded artifacts. However, Gradle's cache includes the dependency cache, wrapper distributions, generated jars, transformed artifacts, and the local build cache. The official action manages which of these to keep.\n\nIn a test project, the Gradle cache saved 22.0 seconds per run, and the Maven cache saved 10.3 seconds. When emptying the dependency directory for both tools, a cold run took 29.3 seconds for Gradle and 14.1 seconds for Maven. With the cache restored, these times dropped to 7.3 seconds for Gradle and 3.8 seconds for Maven.\n\nTo manage caches effectively, it is recommended to use actions/setup-java for Maven and gradle/actions/setup-gradle for Gradle. Avoid using actions/cache on the Gradle User Home or pairing actions/setup-java with cache: gradle, as this can cause conflicts. Additionally, note that setup-gradle only writes cache entries from jobs on the default branch, meaning long-lived feature branches may still download missing dependencies on each run.",
  "summary": "To cache Gradle GitHub Actions runs, use gradle/actions/setup-gradle , which keeps the whole Gradle User Home rather than the dependency folder alone; for Maven, use actions/setup-java with cache: maven , which is a managed actions/cache over ~/.m2/repository . On one small Spring project measured on a Latchkey runner, the Gradle cache was worth 22.0 seconds a run and the Maven cache 10.3…",
  "key_points": [
    "Gradle cache saved 22.0 seconds per run in test project",
    "Maven cache saved 10.3 seconds in test project",
    "Use dedicated actions for Maven and Gradle to manage caches"
  ],
  "editors_take": "Implementing specialized caching actions streamlines continuous integration workflows by significantly reducing build durations through the strategic preservation of dependency directories and local build artifacts.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}