本文以spring-boot-maven-plugin 2.5.4為例
@Mojo defaultPhase
以spring-boot-maven-plugin:start為例, 他的@Mojo defaultPhase是PRE_INTEGRATION_TEST,該目標默認綁定到此階段.
1
2
3
4
|
@Mojo (name = "start" , requiresProject = true , defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST) public class StartMojo extends AbstractRunMojo { } |
在pom中,我們只需要指定goal,就會在PRE_INTEGRATION_TEST階段執(zhí)行
1
2
3
4
5
6
7
8
9
10
11
12
|
< 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階段執(zhí)行--> < phase >verify</ phase > </ execution > </ executions > |
@Execute phase
以spring-boot-maven-plugin:run為例,他的@Execute phase=TEST_COMPILE,在運行該目標前,讓maven先運行一個并行的生命周期,到指定的階段TEST_COMPLIE為止。到phase執(zhí)行完,才執(zhí)行插件目標
所以執(zhí)行run,總是會運行到TEST_COMPLIE階段
1
2
3
4
|
@Mojo (name = "run" , requiresProject = true , defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST) @Execute (phase = LifecyclePhase.TEST_COMPILE) public class RunMojo extends AbstractRunMojo { |
參考資料
到此這篇關(guān)于Maven Plugin的@Mojo和@Execute的具體使用的文章就介紹到這了,更多相關(guān)Maven Plugin @Mojo和@Execute內(nèi)容請搜索服務器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務器之家!
原文鏈接:https://juejin.cn/post/7006505209052528648