question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle cache increases by 400 MB every time updating Gradle wrapper version

See original GitHub issue

Description: When updating the Gradle wrapper to a new version (changed gradle-wrapper.properties), then

  1. setup-java@v2 first restores the gradle cache from previous run (why??)
  2. new Gradle version is downloaded and build
  3. then setup-java@v2 creates a new cache file (~800 MB) which is about 400 MB larger than before because it contains two Gradle versions

Changing Gradle wrapper version again increases the cache file size by 400 MB to 1200 MB, and so on…

Here is a run where it happened: https://github.com/JFormDesigner/FlatLaf/runs/4705134891

In “Setup Java 17” the outdated cache is restored (https://github.com/JFormDesigner/FlatLaf/runs/4705134891#step:4:35):

Cache Size: ~425 MB (445413982 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/19b74bcf-0264-4065-b1ef-448c93c2d4fc/cache.tzst -P -C /home/runner/work/FlatLaf/FlatLaf
Cache restored successfully
Cache restored from key: setup-java-Linux-gradle-707ed6f8250ea8ec2ee660640962308e354fe354d36338715ef1bcab4fcc837f

In “Post Setup Java 17” a new cache with ~836 MB is created (https://github.com/JFormDesigner/FlatLaf/runs/4705134891#step:11:5):

Cache Size: ~836 MB (876885346 B)
Cache saved successfully
Cache saved with the key: setup-java-Linux-gradle-af7e537f7a03362010edc6596ab7fba05bdfb901982028cbd2d21e5291cd932d

Note the different hash keys in the cache file names!

Task version: actions/checkout@v2

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
See above description.

Expected behavior: When changing gradle-wrapper.properties (or build.gradle), then the cache should be not restored.

Actual behavior: Cache is restored even if gradle-wrapper.properties (or build.gradle) changed, which increases the size of the cache file by aboud 400 MB every time a new Gradle wrapper version is used.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
dsamecommented, Jul 16, 2022

I put my suggestion into a PR here to make it more clear what I mean to prevent this problem.

The PR is merged now, and the workaround i’ve suggested in the reply will become unnecessary on next release.

2reactions
mandrachekcommented, Apr 29, 2022

@schuenadel - that’s exactly the approach I wound up taking.

@fl250144 - here’s what I used instead of the built-in cache:

  # This works around an issue in setup-java which allows the dependency cache to grow each time the gradle wrapper is upgraded 
 ​      - ​name​: ​Cache Gradle Wrapper and Dependencies 
 ​        ​uses​: ​actions/cache@v3 
 ​        ​with​: 
 ​          ​path​: ​| 
 ​            ~/.gradle/caches 
 ​            ~/.gradle/wrapper 
 ​          ​key​: ​${{ runner.os }}-gradle-cache-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', '**/gradle/wrapper/gradle-wrapper.properties') }}

It adds the hash of gradle-wrapper.properties, so when the gradle version is updated, the cache is rebuilt.

My cache is now back down under a gig.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Gradle Wrapper - Gradle User Manual
One way to upgrade the Gradle version is manually change the distributionUrl property in the Wrapper's gradle-wrapper.properties file. The better and ...
Read more >
Plugin gradle config: building downloads the same version
The problem is everytime I do ' gradle build', it re-dlownloads the intellij distribution (of 400 MB). Shouldn't it be cached? 1.
Read more >
Top Android Build Issues and how to fix them | Gradle Enterprise
Using the build cache to accelerate developer and CI builds; Using build scans to optimize and debug collaboratively.
Read more >
android - How to clear gradle cache? - Stack Overflow
NOTE: Android Studio's File > Invalidate Caches / Restart doesn't clear the Android build cache, so you'll have to clean it separately. On...
Read more >
Make your Gradle builds fast again! | by Łukasz Wasylkowski
You can update gradle wrapper from Android Studio as well — open ProjectStructure dialog and update Gradle version field in Project tab.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found