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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

sabersword   2021-09-13 我要评论
想了解Maven Plugin的@Mojo和@Execute的具体使用的相关内容吗,sabersword在本文为您仔细讲解Maven Plugin @Mojo和@Execute的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Maven,Plugin,@Mojo,Maven,Plugin,@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官方
博客

到此这篇关于Maven Plugin的@Mojo和@Execute的具体使用的文章就介绍到这了,更多相关Maven Plugin @Mojo和@Execute内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们