【问题标题】:Two Maven plugin with same execution phase两个执行阶段相同的 Maven 插件
【发布时间】:2019-07-17 11:31:05
【问题描述】:

如果一个失败,两个maven插件是否可以执行相同的生命周期?

例子:

假设我有以下插件配置,

<plugins>
  <plugin>
    <groupId>smothing</groupId>
    <artifactId>plugin-1</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
        <id>doSomthing</id>
        <phase>test</phase>
        //...//
  </plugin>

  <plugin>
    <groupId>something</groupId>
    <artifactId>plugin-2</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
        <id>doSomthingAgain</id>
        <phase>test</phase>
        //...
  </plugin>
</plugins>

即使第一个插件失败,我也想执行 plugin-2 测试阶段。我不想忽略或跳过测试用例。

即使一个失败,我也有以下两个插件在同一阶段执行。

<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>

<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>

基本上,在仪表测试之后,我想通过 maven exec 插件执行一些清理活动。那么我有什么选择总是执行 maven exec 插件吗? (没有命令行参数,这是我在 pom.xml 中所期待的)

我看过这些答案,但都说要跳过测试用例。

How to run a maven goal when there is tests failures?

Maven reporting plugins do not execute if a unit test failure occurs

非常感谢任何帮助:)

【问题讨论】:

    标签: java maven gauge


    【解决方案1】:

    如果插件失败,它将停止生命周期的执行。所以你不应该试图通过考虑在某些情况下执行另一个插件来解决它。 根据您的描述,最好的方法似乎是编写扩展程序,请参阅 https://maven.apache.org/examples/maven-3-lifecycle-extensions.html 。使用https://maven.apache.org/ref/3.6.0/maven-core/apidocs/index.html?org/apache/maven/execution/AbstractExecutionListener.html,您可以看到您可以在生命周期的任何部分之前或之后执行操作,例如projectSucceeded+projectFailed 后清理

    【讨论】:

    • 谢谢你的回答:)
    最近更新 更多