Search code examples
mavenmaven-plugincucumber-jvmtest-reporting

Maven Plugin conflict


What all i want to do is run test in phase integration-test and then generate report. by mvn verify

But only test are executed report never runs. When i comment first plugin then other is executed. Any idea how to fix it?

I have below in my 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>

Solution

  • The problem is due to the fact that cucumber.api.cli.Main calls System.exit and therefore terminates the Maven process before the other plugin gets to be executed.

    One way to fix the problem would be to use the exec goal of the exec-maven-plugin, rather than the java goal, as it runs in a separate process.

    However, a better (and easier) solution is to define a JUnit test that will configure and run your cucumber tests, for example:

    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 {
    }
    

    You can then use either the maven-surefire-plugin or the maven-failsafe-plugin plugin to execute that test. The maven-cucumber-reporting plugin will then execute successfully and create the report.

    You can see this in action on a github branch I have just pushed.