您如何强制在构建结束时仅将一次maven MOJO执行一次? [英] How do you force a maven MOJO to be executed only once at the end of a build?
本文介绍了您如何强制在构建结束时仅将一次maven MOJO执行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一次要执行的MOJO,并且仅在反应堆中最后一个项目的测试阶段要运行之后执行一次.
I have a MOJO I would like executed once, and once only after the test phase of the last project in the reactor to run.
使用:
if (!getProject().isExecutionRoot()) {
return ;
}
在execute()方法开始时,
表示我的mojo被执行一次,但是在构建的开始-在所有其他子模块之前.
at the start of the execute() method means my mojo gets executed once, however at the very beginning of the build - before all other child modules.
推荐答案
为此找到的最佳解决方案是:
The best solution I have found for this is:
/**
* The projects in the reactor.
*
* @parameter expression="${reactorProjects}"
* @readonly
*/
private List reactorProjects;
public void execute() throws MojoExecutionException {
// only execute this mojo once, on the very last project in the reactor
final int size = reactorProjects.size();
MavenProject lastProject = (MavenProject) reactorProjects.get(size - 1);
if (lastProject != getProject()) {
return;
}
// do work
...
}
这似乎适用于我测试过的小型构建层次结构.
This appears to work on the small build hierarchies I've tested with.
这篇关于您如何强制在构建结束时仅将一次maven MOJO执行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文