如何从 Maven 存储库中清除旧的依赖项?
我在 .m2 文件夹中有太多文件,maven 存储下载的依赖项.有没有办法清理所有旧的依赖项?例如,如果存在具有 3 个不同版本的依赖项:1、2 和 3,则清理后必须只有 3rd.我如何为 .m2 文件夹中的所有依赖项执行此操作?
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?
推荐答案
如果你在 Unix 上,你可以使用那里文件的访问时间.只需为您的文件系统启用访问时间,然后运行您想要保留依赖项的所有项目的干净构建,然后执行类似这样的操作(未测试!):
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
这将找到最后一次访问超过 5 分钟的所有 *.pom 文件(假设您开始构建最多 5 分钟前)并删除它们的目录.
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.
在 rm 之前添加echo"以进行试运行".
Add "echo " before the rm to do a 'dry-run'.
相关文章