如果一个失败,是否可以执行两个 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 插件执行一些清理 Activity 。那么我有什么选择可以始终执行 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
非常感谢任何帮助:)
最佳答案
如果插件失败,它将停止生命周期的执行。因此,您不应该尝试通过考虑在某些情况下执行另一个插件来解决它。 根据您的描述,最好的方法似乎是编写扩展,请参阅 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之后进行清理
关于java - 两个具有相同执行阶段的 Maven 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54842874/