How do you force a maven MOJO to be executed only once at the end of a build?

前端 未结 7 1614
傲寒
傲寒 2021-02-08 13:06

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.

Using:

if (!getProject().isExecut         


        
7条回答
  •  梦谈多话
    2021-02-08 13:50

    There is a Sonatype blog entry that describes how to do this. The last project to be run will be the root project as it will contain module references to the rest. Thereforec you need a test in your mojo to check if the current project's directory is the same as the directory from where Maven was launched:

    boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir.toString());
    

    In the referenced entry there is a pretty comprehensive example of how to use this in your mojo.

提交回复
热议问题