gtu*_*rri 2 maven-plugin maven
TL; DR:使用maven,我想test在测试实际运行之前在阶段开始时运行一个插件目标.什么是干净的方式呢?
我想在测试实际运行之前打印一条消息.因此,我想在测试阶段开始时使用echo插件的echo目标(告诉用户如果每个测试都失败了,他最好看一下,因为他应该首先设置一个测试环境)README
尝试n°1
一个简单的办法可以是运行这个插件在前一阶段,process-test-classes.
它有效,但将此任务绑定到此阶段似乎在语义上不正确...
尝试n°2
根据Maven文档,When multiple executions are given that match a particular phase, they are executed in the order specified in the POM, with inherited executions running first.我试图明确设置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>
...
Run Code Online (Sandbox Code Playgroud)
但测试在我的消息打印之前运行.
所以,简而言之:有没有办法达到我的目标,或者我应该坚持" process-test-classes解决方案",即使它看起来有点"hacky"?
谢谢!
正如@khmarbaise所说,你的解决方案仍然是hacky,因为整个测试看起来像集成测试,应该由Failsafe插件处理.Failsafe有很好pre-integration-test的测试假wiki等的阶段:)
根据配置默认Mojo执行指南,这对我有用:
<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>
Run Code Online (Sandbox Code Playgroud)
这对我来说很奇怪;)
我有两个插件,执行绑定到generate-sources,一个列在大约6个插件的列表中,另一个列在最后.但是,最后列出的那个(取决于首先列出的那个)总是先执行.
如何在单个阶段中执行多个maven插件并设置各自的执行顺序?
| 归档时间: |
|
| 查看次数: |
1066 次 |
| 最近记录: |