如何清理maven仓库中的旧依赖? [英] How to clean old dependencies from maven repositories?

查看:1631
本文介绍了如何清理maven仓库中的旧依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.m2文件夹中有太多的文件,其中maven存储下载的依赖项。有没有办法清理所有旧的依赖关系?例如,如果有3个不同版本的依赖关系:1,2和3,清理后必须只有3。如何使用.m2文件夹中的所有依赖项?

解决方案

如果您使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆