Home > database >  Skip maven-cucumber-reporting plugin when integration test is skipped
Skip maven-cucumber-reporting plugin when integration test is skipped

Time:09-07

This is a basic level question about maven plugin lifecycle.

When I run the command mvn clean install -Dskip.integration.tests=false then cucumber report is generated by the following plugin:

<plugin>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <executions>
          <execution>
            <id>execution</id>
            <phase>verify</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <projectName>${project.name}</projectName>
              <inputDirectory>${project.build.directory}/cucumber</inputDirectory>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <jsonFiles>
                <jsonFile>cucumber.json</jsonFile>
              </jsonFiles>
            </configuration>
          </execution>
        </executions>
      </plugin>

If I skip the integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the maven build fails with the following error:

Execution execution of goal net.masterthought:maven-cucumber-reporting:5.5.0:generate failed: basedir app/target/cucumber does not exist

To what phase should the plugin be configured so that the maven build does not fail when integration test is skipped?

CodePudding user response:

Add the skip variable to the plugin config whose value is based on whether the integration tests are skipped or not.

<plugin>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <executions>
          <execution>
            <id>execution</id>
            <phase>verify</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <skip>${skip.integration.tests}</skip>
              <projectName>${project.name}</projectName>
              <inputDirectory>${project.build.directory}/cucumber</inputDirectory>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <jsonFiles>
                <jsonFile>cucumber.json</jsonFile>
              </jsonFiles>
            </configuration>
          </execution>
        </executions>
      </plugin>

in root pom.xml in the properties section add:

<skip.integration.tests>true</skip.integration.tests>

Now the plugin generates cucumber-html-reports folder when you run the maven command mvn clean install -Dskip.integration.tests=false. If you skip integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the cucumber-html-reports folder will not be generated but maven build would still succeed.

  • Related