【问题标题】:How do I run the maven exec plugin multiple times in a build如何在构建中多次运行 maven exec 插件
【发布时间】:2016-05-26 21:10:56
【问题描述】:

以下是我的 POM 的相关部分 -

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
        <execution>
            <id>StartHub</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-jar</argument>
                    <argument>${basedir}/src/lib/Hub/selenium-server-standalone-2.53.0.jar</argument>
                    <argument>-role</argument>
                    <argument>hub</argument>
                    <argument>-throwOnCapabilityNotPresent</argument>
                    <argument>false</argument>
                    <argument>-newSessionWaitTimeout</argument>
                    <argument>20000</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>StartNode</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-jar</argument>
                    <argument>${basedir}/src/lib/Node/selenium-server-standalone-2.53.0.jar</argument>
                    <argument>-hub</argument>
                    <argument>http://127.0.0.1:4444/register/grid</argument>
                    <argument>-port</argument>
                    <argument>5555</argument>
                    <argument>
                        Dwebdriver.chrome.driver=${basedir}/chromedriver.exe</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

我试图使用 exec 插件在两种配置(集线器和节点)中执行 jar(selenium 独立服务器)。

我的问题是 jar 在第一对“执行”标签之间指定的配置中只执行一次。我已经广泛搜索了一个解决方案,我唯一发现的是不同执行的 id 需要不同,我纠正了这一点。即使我可以成功运行其中任何一个,如果我注释掉另一个的执行,我似乎仍然无法设法运行两次。

我还应该提到我在 Eclipse 中运行该项目,所以理想情况下我想要做的是右键单击 POM.xml 单击 Run-as 并选择“Maven 测试”。

【问题讨论】:

    标签: java maven-3 selenium-grid exec-maven-plugin


    【解决方案1】:

    这不是 Maven 执行问题,而是与您正在执行的内容相关的问题:阻塞进程(第一台服务器)将停止构建监听一个永远不会连接的节点(因为它的执行不会开始)。

    将您的 pom 更改为以下内容:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.5.0</version>
        <executions>
            <execution>
                <id>StartHub</id>
                <phase>test</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-version</argument>
                    </arguments>
                </configuration>
            </execution>
            <execution>
                <id>StartNode</id>
                <phase>test</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-version</argument>
                    </arguments>
                </configuration>
            <a/execution>
        </executions>
    </plugin>
    

    它将完美地执行两个 exec 执行,打印两倍的 Java 版本。注意:sn-p 是您问题的复制和粘贴,只是将java 命令的参数替换为其version 选项。


    您最可能寻找的是在后台或至少以非阻塞方式执行这两个命令,以便执行第二个命令,然后继续构建(执行一些我假设的测试)。

    查看this SO question 了解如何实现它:不要使用exec-maven-plugin,而是使用maven-antrun-plugin 来启动两个selenium 命令。


    进一步说明,您可能应该考虑改用maven-failsafe-plugin 并执行集成测试,将上面的执行附加到pre-integration-test 阶段并在post-integration-test 阶段停止它们以便正确清理它们。

    【讨论】:

    • 非常感谢您的回答。我已经使用流程构建器处理了这个问题,但很高兴知道它为什么不起作用以及 Antrun 插件。我知道故障安全插件,但我没有选择它,因为在使用 testNG 提供的注释无法处理的测试之前和之后我不需要做任何事情。我很想知道通过 Maven 处理此类任务是否比以编程方式处理具有任何内在优势。但我想这完全是一个不同的问题!再次感谢您的宝贵时间!!我接受这个作为答案
    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 2011-12-23
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多