且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

您如何强制在构建结束时仅将一次maven MOJO执行一次?

更新时间:2023-09-26 11:19:28

为此找到的***解决方案是:

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.