清除构建机器上的 Maven 本地存储库
在 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Maven 依赖插件有一个 purge-local-repository 目标允许您从本地存储库中删除给定项目的依赖项,如果每天在每个项目上运行一次,则快照将不会累积。
或者,您可以采取更焦土的方法。 由于问题通常是带时间戳的快照工件,因此您可以使用 maven-antrun-plugin< /a> 删除所有与资源收集模式匹配的文件。
例如(请注意,这可能需要一些调整,因为我是凭记忆完成的):
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.
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):
如果您使用的是 hudson,您可以设置一个计划作业,每天删除整个存储库一次或类似的操作。 我有一个名为 hudson-maven-repo-clean 的作业,它具有以下配置:
0 0 * * *
If you're using hudson, you can set up a scheduled job to just delete the entire repository once a day or something like that. I've got a job called
hudson-maven-repo-clean
which has this configuration:rm -rf ~hudson/.m2/repository
0 0 * * *
除了 purge-local-repository(对我来说,它就像一个核选项,因为它只提供
excludes
配置,而不是显式includes
),看看在删除项目工件mojo 。 我现在正在考虑实现它,因为我的确切用例是清除在我的 CI(有时是工作站)机器上构建的大型 WAR 和 EAR 快照。In addition to purge-local-repository (which reads to me like a nuclear option, as it only offers an
excludes
configuration as opposed to an explicitincludes
), take a look at the Remove Project Artifact mojo. I'm looking to implement it now, as my exact use case is to clear out large WAR and EAR snapshots that are being built on my CI (and sometimes workstation) machines.为此,我们特别使用 build-helper 插件。 在我们公司的父 pom 中,remove-project-artifact 目标嵌入在我们的 hudson 构建的配置文件中。 这样,在安装当前构建版本之前,该工件的所有旧版本都会被删除。
使用将removeAll 设置为true 将清除除您正在处理的快照之外的所有其他快照。 这可能很危险,因为它可能意味着分支的快照也将被删除。
例如,如果您有代表 HEAD 的快照 1.0.0.18-SNAPSHOT 和代表分支的快照 1.0.1.17-SNAPSHOT,则使用 1.0.0.18-SNAPSHOT 版本运行此插件将擦除 1.0.1.17-SNAPSHOT 文件夹。
为了解决这种情况,removeAll 应设置为 false。
We use especially for this purpose the build-helper plugin. In our company parent pom is the remove-project-artifact goal embedded in the profile for our hudson builds. This way all old versions of this artifact are removed prior to installing the currently build version.
Using removeAll set to true will wipe out all other snapshots except the one your working on. This can be dangerous as it may mean snapshots for a branch will be wiped out as well.
For instance if you have a snapshot 1.0.0.18-SNAPSHOT representing HEAD and snapshot 1.0.1.17-SNAPSHOT representing a branch, running this plugin with 1.0.0.18-SNAPSHOT build will wipe the 1.0.1.17-SNAPSHOt folder.
To get around this scenario the removeAll should be set to false.
我们采用了一种略有不同(且狡猾)的技术。 所有构建“大型事物”(EAR、WAR、TAR)的工件都会像这样覆盖其部署位置:
此策略导致部署目标将事物放入目标目录中,该目录当然会被下一个 CLEAN 操作破坏。 为了变得更加积极,我们有一个构建后步骤来做到这一点:
我们还采用了另一种策略。 在 Hudson/Jenkins 中,我们提供了一个设置文件,用于将 .m2 存储库放置在作业的工作空间中。 这允许我们在作业之前或之后删除整个存储库。 它还使工件在工作区中可见,这有助于调试一些问题。
We have employed a slightly different (and devious) technique. All artifacts that build "large things" (EARs, WARs, TARs) have their deploy location overriden like so:
This strategy causes the deploy goal to put things in the target directory, which of course is destroyed by the next CLEAN operation. To get even more aggressive, we have a postbuild step that does this:
We employ yet one more strategy, too. In Hudson/Jenkins we provide a settings file to place the .m2 repository in the workspace for the job. This allows us to delete the entire repository before or after the job. It also makes artifacts visible in the workspace which aids in debugging some problems.
文件系统有多大? 我们每晚分配 10GB 来构建和删除 30 天以上的快照。 这似乎有效
您是否每隔 X 小时或在代码更改时进行构建? 切换到代码更改将减少工件数量,而不会降低覆盖范围。
您是否在本地安装所有快照? 您不需要在所有情况下都这样做。 在大多数情况下,只有那些主动开发依赖项的快照需要在本地安装。
您是否在本地安装 EAR/WAR 文件? 您可能也不需要它们。
您保留了多少个工作空间? 我们使用 hudson 并仅保留最后 5 个版本。
How big is the file system? We have 10gb allocated to builds and zap snapshots older than 30 days every night. That seems to work
Are you doing builds every X hours or when code changes? Switching to code changes will reduce the number of artifacts without reducing coverage.
Are you installing all snapshots locally? You don't need to do this in all cases. In most cases, just those snapshots that are actively developed dependancies need to be installed locally.
Are you installing EAR/WAR files locally? You probably don't need them either.
How many workspaces are you keeping? We use hudson and keep only the last 5 builds.