• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

java 搞代码 4年前 (2022-01-09) 31次浏览 已收录 0个评论

本文以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

本文来源gaodai#ma#com搞*!代#%^码$网*

以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 Plugin的@Mojo和@Execute的具体使用的文章就介绍到这了,更多相关Maven Plugin @Mojo和@Execute内容请搜索搞代码以前的文章或继续浏览下面的相关文章希望大家以后多多支持搞代码! 


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Maven Plugin的@Mojo和@Execute的具体使用
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址