在一个阶段中多次运行exec-maven-plugin [英] Running exec-maven-plugin multiple times in a single phase

查看:678
本文介绍了在一个阶段中多次运行exec-maven-plugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试客户端/服务器应用程序,并使用Maven处理构建/测试/部署.要测试该应用程序,我需要:

I'm trying to test a client/server application, and using Maven to handle the build/test/deploy. To test the application, I need to:

  1. 运行安装程序脚本(以安装服务器),
  2. 启动命令(启动服务)
  3. 运行测试(maven-surefire-plugin),
  4. 停止服务,并且
  5. 卸载服务.

步骤1,2,4和5将使用maven-exec-plugin.第3步将使用maven-surefire-plugin.

Steps 1,2,4 and 5 will use the maven-exec-plugin. Step 3 will use the maven-surefire-plugin.

问题在于所有这五个步骤都将在测试"阶段进行. Maven允许以特定顺序执行插件. exec-plugin可以通过使用多个条目多次运行.问题是我需要在4个exec-plugin执行中使用surefire-plugin.

The problem is that all 5 of these steps will occur in the 'test' phase. Maven allows plugins in to be executed in a specific order. the exec-plugin can be run multiple times by using multiple entries. The problem is that I need to use the surefire-plugin in the middle of the 4 exec-plugin executions.

以前有没有人碰过这个,或者知道如何构造插件和执行的结构?

Has anyone ever run into this before, or know how to structure the plugin's and execution's?

推荐答案

您尝试做的事情听起来更像是集成测试而不是单元测试.对于此用例,默认的maven生命周期具有与集成测试有关的三个阶段:

What you are trying to do sounds more like an integration test than a unit test. For this use case the default maven lifecycle has three phases related to integration testing:

  • pre-integration-test:执行集成测试之前所需的操作.这可能涉及诸如设置所需环境之类的事情.
  • integration-test:处理该程序包并将其部署到可以运行集成测试的环境中.
  • post-integration-test:执行集成测试后执行所需的操作.这可能包括清理环境.
  • pre-integration-test: perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run.
  • post-integration-test: perform actions required after integration tests have been executed. This may including cleaning up the environment.

surefire插件通常在test阶段执行,但可以重新配置为在另一个阶段执行.然后,您可以将步骤1 + 2配置为在pre-integration-test中执行,而步骤4 + 5必须在post-integration-test中执行.

The surefire plugin usually executes in the test phase, but can be reconfigured to execute in another phase. Your steps 1 + 2 can then be configured to execute in pre-integration-test, while steps 4 + 5 have to execute in post-integration-test.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <!-- Skip execution in test phase and execute in integration-test phase instead -->
    <configuration>
        <skip>true</skip>
    </configuration>
    <executions>
        <execution>
            <id>surefire-it</id>
            <phase>integration-test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <skip>false</skip>
            </configuration>
        </execution>
    </executions>
</plugin>

这篇关于在一个阶段中多次运行exec-maven-plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆