简体   繁体   English

CI服务器上的Maven并发构建

[英]Maven concurrent builds on CI server

I have an interesting case, in my opinion.在我看来,我有一个有趣的案例。 We are using maven, and being that we have to support multiple versions of our product we sometimes have a 1.x and 2.x build structure going on.我们正在使用 maven,由于我们必须支持我们产品的多个版本,因此我们有时会使用 1.x 和 2.x 构建结构。 When both 1.x and 2.x are built in parallel, sometimes we see当 1.x 和 2.x 并行构建时,有时我们会看到

Error installing artifact's metadata: Error installing metadata: Error updating group repository metadata安装工件的元数据时出错:安装元数据时出错:更新组存储库元数据时出错

From what I can tell, the maven-metadata-local.xml in the local user's repo (for the artifact, not the version of the artifact) is being written to at the same time by another maven process.据我所知,本地用户存储库中的 maven-metadata-local.xml(对于工件,而不是工件的版本)正在同时被另一个 maven 进程写入。 Is there a way to allow maven to build both of these in parallel, but wait for a write lock on the file to update it?有没有办法让 maven 并行构建这两个,但等待文件上的写锁来更新它?

That sounds that you are using the same local repository for all your build jobs which will not work as you already know.听起来您正在为所有构建作业使用相同的本地存储库,而您已经知道这些作业将无法正常工作。 The point in Jenkins/Hudson/CI is to use a local maven repository for every build job. Jenkins/Hudson/CI 的重点是为每个构建作业使用本地 maven 存储库。 You need to configure in Jenkins using a local maven repository to avoid such situations.您需要在 Jenkins 中使用本地 maven 存储库进行配置以避免此类情况。

You could also install the Concurrent Safe Local Repository Access maven plugins which will allow you to use the same local repository.您还可以安装并发安全本地存储库访问maven 插件,这将允许您使用相同的本地存储库。 (Useful if you are dynamically provisioning the agents) (如果您正在动态配置代理,则很有用)

Use the 2nd or 3rd option under Maven settings (Admin/Configure):使用 Maven 设置 (Admin/Configure) 下的第二个或第三个选项: 在此处输入图像描述

These options come from the: Maven Project Plugin这些选项来自: Maven 项目插件

It's now possible to access repository concurrently starting from maven 3.8.2现在可以从maven 3.8.2开始同时访问存储库

Require manual libraries installation & config for concurrent-safe access需要手动安装和配置库以实现并发安全访问

Here a snippet to setup maven 3.8 in /opt/mvn with concurrent-safe repo access (local redis installation required).这里是在/opt/mvn中设置 maven 3.8 并具有并发安全 repo 访问权限的片段(需要本地 redis 安装)。 It can be used in Dockerfile RUN or directly:可以在 Dockerfile RUN中使用,也可以直接使用:

cd /opt \
  && wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.zip \
  && unzip apache-maven-*.zip && rm apache-maven-*.zip \
  && ln -s /opt/apache-maven-* /opt/mvn \
  && wget https://gist.githubusercontent.com/valodzka/85bc9fa1af8b6f8c876e99267d22933f/raw/4d18ae882cd624382d508c0217682a874a0744b2/redisson-sync-context-urls.txt \
  && wget --directory-prefix=/opt/mvn/lib/ext/redisson --input-file=redisson-sync-context-urls.txt \
  && sed --in-place '/logging/a load ${maven.home}/lib/ext/redisson/*.jar' /opt/mvn/bin/m2.conf \
  && rm redisson-sync-context-urls.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM