Gradle cache growing indefinitely

Hi all,

Is there ANY mechanism in gradle cache to delete old snapshot artifacts? Caches on our build servers seem to be growin indefinitely and can take up to several GBs. We continuously build with new snapshot artifacts several times per day and gradle cache seems to be collecting ALL those artifacts. Is there a way to tell Gradle cache to delete all SNAPSHOT artifacts but last one (or few last ones …)? Thanks.

Matthew

That’s certainly an aspect of the Gradle cache we’d like to optimize. It would make sense to delete caches of older (and potentially unused) Gradle versions after a while. The same is true for outdated SNAPSHOT versions. At the moment there’s no way to tell Gradle to delete old dependency artifacts from the cache.

It would certainly be great if we could have the functionality in Gradle core. If you are interested in contributing, a good place to start would a discussion on the Gradle dev list.

Hello,
Facing similar issue again… Do we have any updates on this cache clearing mechanism in gradle with latest releases.
Is there any option available to delete old artifacts from gradle cache.

Thanks

It is long implemented already.
All artifacts that were not used by any build in the last 30 days should get automatically cleaned.

1 Like

Thank you @Vampire , Could you please share any reference or link for this.

Also is it possible to handle these artifacts programmatically in gradle?

Could you please share any reference or link for this.

Sure, actually it is 30 days for normal dependencies, 7 days for snapshot dependencies:
https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:cache_cleanup
https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home:cache_cleanup

You can also configure the retention periods as shown in the second link.
But you shouldn’t do it in a settings script of a concrete project, as any other project would still do the cleanup for those common caches.
So if you want to configure it, do it in an init script as shown in the docs, then it also just works for you and not for anyone executing that build.

Also is it possible to handle these artifacts programmatically in gradle?

I don’t think so, not more then configuring the retention periods or just accessing them as files.

1 Like

Hello @Vampire ,

Does the cache retention values applicable for downloaded artifacts? These artifacts will be downloaded as part of custom tasks execution from external artifactories like JFrog.

Thank you.

Depends on how these artifacts are downloaded.
If the Gradle dependency resolution mechanism is used, for example by creating a detached configuration and using that to download the artifacts, then they should be part of the retention logic, yes.
If the custom task uses some arbitrary way to download artifacts like directly using an HTTP client or similar, then of course not, as then those downloads are not under Gradles control.

1 Like