gpt4 book ai didi

maven - 在默认目标之前运行插件目标

转载 作者:行者123 更新时间:2023-12-02 07:31:23 28 4
gpt4 key购买 nike

TL;DR:使用 maven,我想在 test 阶段开始时运行一个插件目标,在测试实际运行之前。什么是干净的方法?


我想在测试实际运行之前打印一条消息。因此我想使用 echo pluginecho 目标在测试阶段开始时(告诉用户,如果每个测试都失败,他最好看一下README,因为他应该先建立一个测试环境)

尝试 n°1

一个简单的方法是在 the previous phase 中运行这个插件。 , 进程测试类

它有效,但将此任务绑定(bind)到此阶段在语义上似乎不正确...

尝试 n°2

根据 Maven documentation , 当给出与特定阶段匹配的多个执行时,它们将按照 POM 中指定的顺序执行,首先运行继承的执行。,所以我尝试显式设置 surefire插件:

...
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>*** If most tests fail, make sure you've installed the fake wiki. See README for more info ***</echo>
</echos>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
...

但是测试在我的消息被打印之前运行。

所以,简而言之:有没有办法实现我的目标,或者我应该坚持“process-test-classes 解决方案”,即使它看起来有点“hacky” “?

谢谢!

最佳答案

正如@khmarbaise 所说,您的解决方案仍然是 hacky,因为整个测试看起来像集成测试,应该由 Failsafe Plugin 处理. Failsafe 有很好的 pre-integration-test 阶段用于测试假 wiki 等 :)

基于 Guide to Configuring Default Mojo Executions这对我有用:

<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>1-test</id>
<phase>test</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>*** If most tests fail, make sure you've installed the fake wiki. See README for more info ***</echo>
</echos>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>2-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>

这对我来说很奇怪;)

I have two plugins with executions bound to generate-sources, one listed first in the list of about 6 plugins and the other listed last. However, the one listed last (which depends on the one listed first) always executes first.

How can I execute several maven plugins within a single phase and set their respective execution order?

关于maven - 在默认目标之前运行插件目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368948/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com