Maven 本地 repo 在一个通用的全局目录中用于多个并行执行

Maven local repo in a common global directory for multiple parallel execution

我有一台机器,其中发生了多个并行 Maven 执行。每次执行都会在单独的工作区目录中执行以下命令

mvn -f main/pom.xml clean package -DskipTests -T 6

有人可以告诉我应该为每次执行使用单独的 Maven 本地存储库路径 (-Dmaven.repo.local=$MAVEN_REPO) 还是可以为所有并行运行使用公共 .m2 目录?通常遵循的做法是什么?

我首先要说的是,可以为每个项目设置多个本地存储库或一个本地存储库。 实际上,方法是为每个项目设置自己的 settings.xml。 每个 settings.xml 都有一个指向不同路径的 localRepository 标签。 项目 运行 的 Dmaven.repo.local=/path/to/repo 标志将执行指向具有特定本地存储库的 settings.xml。

通常根本不需要。 Maven 可以处理并行执行,并且为您的所有项目(其中安装和下载所有工件)提供一个中央本地存储库可以促进它们的处理并且不会缩短构建时间。 它可以影响你的唯一方法是,如果你的一个项目需要另一个项目创建的工件——但这也不应该由多个本地存储库处理。

您不能在执行之间共享本地存储库。它们的实现无法容忍多个并发进程访问它们。您可以而且应该 运行 在您的进程和 Internet 上的存储库之间设置一个本地缓存存储库管理器。可以分享。

maven user mailing list 也对此进行了讨论。讨论总结

Hello,

It is the other way around, there might be situations where one job relies on the installed artifacts from the other, in this case you would need a shared Repo. It is however bad style. In all other cases you can use a executor- or even workspace-local local repository if you have enough space.

The advantage of avoiding concurrent access is that you get less influences from one job to the other (especially if you work with snapshots or multiple different upstream artifacts with same version in different Repos) and that there is no concurrent downloads (which in itself sometimes leads to checksum errors).

Gruss Bernd