How to clean old dependencies from maven repositories?(如何从 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'.
这篇关于如何从 Maven 存储库中清除旧的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Maven 存储库中清除旧的依赖项?


基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01