如何从 Maven 存储库中清除旧的依赖项?

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

JPMS/Jigsaw Missing Main Class in Module(JPMS/Jigsaw模块中缺少主类)
Can not run JAVAFX .jar File (many errors occurred)(无法运行JavaFX.jar文件(出现许多错误))
JPMS and fatuber executable JAR - how it works together?(JPMS和FATUBER可执行JAR--它是如何协同工作的?)
Use jdk.internal.net.http(使用jdk.inder.net.http)
javax.annotation classes and Java 11 JDK(Javax.Annotation类和Java 11 JDK)
Are Filer#39;s originating elements useful?(FILLER的原始元素有用吗?)