软件编程
位置:首页>> 软件编程>> java编程>> Maven Plugin的@Mojo和@Execute的具体使用

Maven Plugin的@Mojo和@Execute的具体使用

作者:sabersword  发布时间:2021-12-19 05:23:17 

标签:Maven,Plugin,@Mojo,@Execute

本文以spring-boot-maven-plugin 2.5.4为例

@Mojo defaultPhase

以spring-boot-maven-plugin:start为例, 他的@Mojo defaultPhase是PRE_INTEGRATION_TEST,该目标默认绑定到此阶段.


@Mojo(name = "start", requiresProject = true, defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST,
     requiresDependencyResolution = ResolutionScope.TEST)
public class StartMojo extends AbstractRunMojo {
}

在pom中,我们只需要指定goal,就会在PRE_INTEGRATION_TEST阶段执行


<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
   <execution>
       <id>start</id>
       <goals>
           <goal>start</goal>
       </goals>
       <!--如果额外指定phase=verify,会忽略defaultPhase,而在verify阶段执行-->
       <phase>verify</phase>
   </execution>
</executions>

@Execute phase

以spring-boot-maven-plugin:run为例,他的@Execute phase=TEST_COMPILE,在运行该目标前,让maven先运行一个并行的生命周期,到指定的阶段TEST_COMPLIE为止。到phase执行完,才执行插件目标
所以执行run,总是会运行到TEST_COMPLIE阶段


@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE,
     requiresDependencyResolution = ResolutionScope.TEST)
@Execute(phase = LifecyclePhase.TEST_COMPILE)
public class RunMojo extends AbstractRunMojo {

参考资料

maven官方
博客

来源:https://juejin.cn/post/7006505209052528648

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com