maven - 在一个阶段多次运行 exec-maven-plugin

标签 maven maven-2 maven-plugin

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

  • 运行安装程序脚本(以安装服务器),
  • 启动启动命令(启动服务),
  • 运行测试(maven-surefire-plugin),
  • 停止服务,然后
  • 卸载服务。

  • 步骤 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/

    相关文章:

    java - eclipse的maven插件有捆绑maven软件吗?

    java - 为什么我可以通过指定路径作为参数来运行这个由 Maven 打包的文件,但不能通过在路径变量中永久设置路径来运行?

    unit-testing - 如何使用 maven 资源也作为测试资源

    maven-2 - 如何在我的本地 repo Maven 中下载和安装 jar

    maven-plugin - apt maven 插件无法生成 Q 类

    java - 以所需格式列出 Maven 项目的依赖项

    maven - 如何使用Gradle实现Maven基本pom文件概念?

    java - 导入项目时如何让Eclipse识别文件夹为 "code folders"?

    java - 设置我使用 Clojure 对纯 Java 库进行单元测试的环境

    maven - 仅在父级中运行 Maven 插件