仅在成功进行单元测试后,Maven多模块才部署到存储库 [英] Maven multi-module deploy to repository only after successful unit tests
问题描述
问题:执行"mvn部署"以使部署部分仅在所有单元测试成功且没有重复处理步骤之后才运行,什么是最佳解决方案?
Question: What is the best solution for executing a 'mvn deploy' such that the deploy part is only run after all unit tests succeed and no processing steps are duplicated?
我希望简单的答案是:执行maven命令"x"(或使用标志),以便可以在不调用默认生命周期中先前目标的情况下运行部署.
I was hoping the simple answer was: Execute maven command 'x' (or use a flag) such that the deploy can be run without invoking the prior goals in the default lifecycle.
遗憾的是,这似乎没有一个简单的答案.我在下面提供了我所遵循的路径的详细信息.
Sadly this does not appear to have a simple answer. I have included the details on the path I have followed so far below.
我们有以下三个要求:
- 执行maven部署目标,以将所有多模块工件部署到远程存储库中.
- 仅在所有项目中的所有单元测试都通过的情况下进行部署.
- 请勿重复任何处理.
我们从简单的"mvn clean deploy"开始,但是我们注意到了两个问题:
We started with simply "mvn clean deploy", however we noticed a couple issues:
- 构建将在完成所有单元测试之前停止:::因此我们添加了--fail-at-end标志
- 部署目标将针对任何成功的模块执行.
这将导致损坏"状态,其中远程存储库可能仅具有部分部署(如果在以后的构建中存在发生故障的模块).
This results in a "corrupted" state where the remote repository may only has a partial deployment (if there were modules with failures later in the build).
我们研究了3种不同的解决方案:
We looked at 3 different solutions:
- 在部署::之前先对工件进行分阶段::对于完全自动化的过程来说,这太繁琐了.
- 使用配置文件覆盖默认生命周期,以使"mvn deploy -Pci-deploy"可以运行而无需调用任何先前的目标::这种方法行之有效,而且速度很快,但这显然是一种非常规的方法.
- 仅运行"mvn clean package",然后仅当成功执行"mvn deploy"时::看来可行,并且似乎在调用目标时受到较小的打击(尽管其中一些目标足够聪明,无法重新处理)一个不变的工作空间)
我向社区提出了这个问题,并提供了我提供的背景信息,以确定是否有(可能)提出以下请求之一的更好的方法或强烈的意见:
I pose this question to the community with the background details I have provided to determine if there is a better approach or a strong opinion regarding (potentially) making one of the following requests:
- 一个新的部署目标,可以与所有其他生命周期目标分开运行,并期望:所有先前的步骤都已经运行,并且将与"mvn deploy"相同地执行部署.
- 部署目标中的一个标志,可以有效地禁用先前的目标.
开箱即用,绝对违反当前惯例:
a little more out of the box and definitely against the current convention:
- 一个标记,该标记将告诉maven在继续之前为所有模块运行[unit]测试目标.
注意:
- 我们正在使用Jenkins,但出于这个问题的目的,CI环境不是复杂的事情.
- 我尝试了"mvn deploy:deploy"目标,但有许多不清楚的错误.
- 我没有将集成测试视为要求的一部分.
2013年8月20日更新
Update 8/20/2013
我测试了延迟部署插件,并确定该工具可以按预期工作,但是花了很长时间.
I tested the deferred deploy plugin and determined that the tool worked as expected, but took way to long.
对于我们的代码库:
- MVN干净部署:针对2:44中执行的所有目标
- mvn全新安装"deferred-deploy-plugin":适用于15分钟内执行的所有目标
- MVN清洁包装; mvn deploy -Pci-deploy一个自定义的构建配置文件,该配置文件将禁用先前执行的目标:
- 所有目标(包括部署):4:30
- 仅部署:1:45
- mvn clean deploy: for all goals executed in 2:44
- mvn clean install 'deferred-deploy-plugin': for all goals executed in 15 min
- mvn clean package; mvn deploy -Pci-deploy a custom build profile that disables the earlier goals executed:
- for all goals (including deploy): 4:30
- deploy only: 1:45
- 所有目标(包括部署):4:40
- 仅部署:1:54
干净的程序包接着部署跳过测试的运行速度比延迟的部署要快,并且实现了我们希望将部署延迟到测试成功之后的速度.
The clean package followed by deploy skipping the tests runs faster than the deferred deploy and accomplished our desire to delay the deploy until after the tests succeed.
在部署生命周期执行并退出每个前述目标(过程,编译,测试,打包等)时,似乎花费了很少的时间.但是,唯一的选择是破解非标准执行,仅节省10秒.
There appears to be a minor time hit for when the deploy lifecycle executes and exits each of the preceding goals (process, compile, test, package, etc). However the only alternative is to hack a non-standard execution, which only saves 10 seconds.
推荐答案
现在有一个新答案.自从2.8版的maven deploy插件以来,就有一种方法可以本地"执行此操作.有关详细信息,请参见吉拉问题.
There's a new answer now. Since version 2.8 of the maven deploy plugin there's a way to do this "natively". See the jira issue for details.
基本上,您至少需要强制使用v2.8的插件
Basically you need to force at least v2.8 of the plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8</version> </plugin>
,并使用新的参数
deployAtEnd
.更多信息此处.此设置通常与installAtEnd
一起使用maven-install-plugin的and use the new parameter
deployAtEnd
. more info here. This setting usually goes along withinstallAtEnd
of the maven-install-plugin这篇关于仅在成功进行单元测试后,Maven多模块才部署到存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!