如何清理maven仓库中的旧依赖? [英] How to clean old dependencies from maven repositories?
问题描述
如果您使用Unix,可以使用访问时间的文件在那里只需启动文件系统的访问时间,然后运行一个干净的构建您想要保留依赖项的所有项目,然后执行此操作(UNTESTED!):
find〜/ .m2 -amin +5 -iname'* .pom'|同时读pom; do parent =`dirname$ pom`; rm -Rf$ parent;完成
这将找到所有* .pom文件,最后被访问超过5分钟前(假设您最多可以在5分钟前开始构建)并删除其目录。
在rm之前添加echo进行干运行。
I have too many files in .m2 folder where maven stores downloaded dependencies. Is there a way to clean all old dependencies? For example, if there is a dependency with 3 different versions: 1, 2 and 3, after cleaning there must be only 3rd. How I can do it for all dependencies in .m2 folder?
If you are on Unix, you could use the access time of the files in there. Just enable access time for your filesystem, then run a clean build of all your projects you would like to keep dependencies for and then do something like this (UNTESTED!):
find ~/.m2 -amin +5 -iname '*.pom' | while read pom; do parent=`dirname "$pom"`; rm -Rf "$parent"; done
This will find all *.pom files which have last been accessed more than 5 minutes ago (assuming you started your builds max 5 minutes ago) and delete their directories.
Add "echo " before the rm to do a 'dry-run'.
这篇关于如何清理maven仓库中的旧依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!