问题描述
在 CI 构建服务器上,本地 Maven 存储库会反复填满文件系统(几天后).在这种情况下,其他人正在采取什么策略来修剪本地存储库?-最大
On a CI build server, the local Maven repository fills up the file system repetitively (after a few days).What strategy are others doing to trim the local repository in such a case?-Max
推荐答案
Maven依赖插件有一个purge-local-repository 目标,允许您从本地存储库中删除给定项目的依赖项,如果每个项目每天运行一次快照不会累积.
The Maven dependency plugin has a purge-local-repository goal that allows you to delete the dependencies for a given project from the local repository, if this is run say once a day on each project the snapshots will not accumulate.
或者,您可以采取更焦土的方法.由于问题通常是时间戳快照工件,您可以使用 maven-antrun-plugin 删除所有符合资源收集模式的文件.
Alternatively there's a more scorched-earth approach you could take. As the problem is typically the timestamped snapshot artifacts, you could use the maven-antrun-plugin to delete all files that match the resource collection pattern.
例如(请注意,这可能需要一些调整,因为我是根据记忆完成的):
For example (note this might need some tweaking as I've done it from memory):
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<delete>
<fileset dir="${settings.localRepository}">
<include name="**/*.jar"/>
<exclude name="**/*.pom"/>
<exclude name="**/*.war"/>
<exclude name="**/*.ear"/>
<exclude name="**/*.md5"/>
<exclude name="**/*.sha"/>
<!--any other extensions?...-->
<!--match the timestamp pattern-->
<containsregexp expression="[0-9]{8}.[0-9]{6}-[0-9]+"/>
</fileset>
</delete>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于在构建机器上清除 Maven 本地存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!