我正在尝试测试客户端/服务器应用程序,并使用 Maven 来处理构建/测试/部署。要测试应用程序,我需要:
步骤 1、2、4 和 5 将使用 maven-exec-plugin。第 3 步将使用 maven-surefire-plugin。
问题是所有这 5 个步骤都将在“测试”阶段发生。 Maven 允许插件按特定顺序执行。 exec-plugin 可以通过使用多个条目多次运行。问题是我需要在 4 个 exec-plugin 执行中间使用 surefire-plugin。
有没有人以前遇到过这个问题,或者知道如何构建插件和执行的结构?
最佳答案
这就是我配置 exec 和故障安全插件的方式。我正在使用故障安全,而不是重新配置surefire,因为surefire仍在运行其他测试以进入测试阶段。这将在 pre-integrationtest 阶段运行第 1 步和第 2 步(为同一阶段列出的多个执行将按照给定的顺序执行),在集成测试阶段运行测试,然后用第 3 步和第 4 步清理后集成测试阶段。
(注意:我用 echo 命令代替了真正的安装和清理命令)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>step1</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>foo</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step2</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>bar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step3</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>baz</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step4</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>woot</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
关于maven - 在一个阶段多次运行 exec-maven-plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9231626/