Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - purge local .m2 from all old artifacts versions

Tags:

maven

I want to clean my local .m2 from all old versions of all artifacts. Leaving only the latest.
I'm aware of the mvn dependency:purge-local-repository option, but it works only with a specific project in mind, and processes only the current project dependencies.
I'm thinking of writing a script to crawl all over the folder and process it, but it feels there might be a better solution...
I want to clean ALL of the .m2.

Any ideas?

like image 242
Eldad Assis Avatar asked Dec 03 '25 21:12

Eldad Assis


1 Answers

This depends on what you're trying to accomplish.

If you just want to reclaim disk space, you can remove all the SNAPSHOTs you have locally:

find ~/.m2/repository -name \*SNAPSHOT -type d -print0 | xargs -0 rm -rf 

If you're trying to bundle up a minimal functional local repository for use on another machine, then I would rename my ~/.m2/repository; do the builds I need then tar up the results.

like image 122
Idcmp Avatar answered Dec 06 '25 11:12

Idcmp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!