This article uses Spring-boot-Maven-plugin 2.5.4 as an example
@Mojo defaultPhase
Take spring-boot-Maven-plugin :start, whose @mojo defaultPhase is PRE_INTEGRATION_TEST, to which the target is bound by default.
@Mojo(name = "start", requiresProject = true, defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)
public class StartMojo extends AbstractRunMojo {}Copy the code
In the POM, we just need to specify goal and it will be executed in the PRE_INTEGRATION_TEST phase
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>start</id>
<goals>
<goal>start</goal>
</goals>
<! -- If phase=verify is specified, defaultPhase is ignored and the verify phase is executed -->
<phase>verify</phase>
</execution>
</executions>
Copy the code
@Execute phase
For example, spring-boot-Maven-plugin :run, @execute Phase =TEST_COMPILE, has Maven run a parallel lifecycle to TEST_COMPLIE before running the target. The plug-in target is not executed until the phase execution is complete so running always reaches the TEST_COMPLIE phase
@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
@Execute(phase = LifecyclePhase.TEST_COMPILE)
public class RunMojo extends AbstractRunMojo {
Copy the code
The resources
Maven official maven.apache.org/developers/… Blog www.cnblogs.com/cxyyh/p/108…