Maven 插件冲突

Maven Plugin conflict

我想做的就是运行阶段集成测试测试,然后生成报告。 通过 mvn 验证

但只执行测试,报告从未 运行s。当我首先评论插件时,然后执行其他插件。知道如何解决吗?

我的 pom 中有以下内容

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <classpathScope>test</classpathScope>
                        <executableDependency>
                            <groupId>info.cukes</groupId>
                            <artifactId>cucumber-core</artifactId>
                        </executableDependency>
                        <mainClass>cucumber.api.cli.Main</mainClass>
                        <arguments>
                            <argument>target/test-classes/feature</argument>
                            <agrument>--glue</agrument>
                            <argument>integration</argument>
                            <argument>src\test\java</argument>
                            <argument>--plugin</argument>
                            <argument>pretty</argument>
                            <argument>--plugin</argument>
                            <argument>html:target/cucumber-report</argument>
                            <argument>--plugin</argument>
                            <argument>json:target/cucumber-report/cucumber.json</argument>
                            <argument>--tags</argument>
                            <argument>~@ignore</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>0.0.8</version>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>poc.selenium.it</projectName>
                        <outputDirectory>target/cucumber-report</outputDirectory>
                        <cucumberOutput>target/cucumber-report/cucumber.json</cucumberOutput>
                        <enableFlashCharts>true</enableFlashCharts>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

问题是由于 cucumber.api.cli.Main calls System.exit 因此在其他插件执行之前终止了 Maven 进程。

解决该问题的一种方法是使用 exec-maven-pluginexec 目标,而不是 java 目标,因为它 运行 在单独的过程。

但是,更好(也更容易)的解决方案是定义一个 JUnit 测试,它将配置和 运行 您的黄瓜测试,例如:

package integration;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "json:target/cucumber-report/cucumber.json")
public class RunTest {
}

然后您可以使用 maven-surefire-pluginmaven-failsafe-plugin 插件来执行该测试。 maven-cucumber-reporting 插件随后将成功执行并创建报告。

您可以在 github branch I have just pushed.

上看到实际效果