本文以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官方 maven.apache.org/developers/…
博客 www.cnblogs.com/cxyyh/p/108…
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END