Cobertura with Maven - Fails if reach below threshold but generates site anyway

I am using Cobertura with Maven.

I would like the assembly to fail if the coverage is below a given threshold, but I would like the site (including the Cobertura report) to still be generated. This is because developers will need to check the coverage report to find out where they can add more features to fix a failed build.

Currently my pom looks like this:

<project> <build> ... <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>${cobertura.version}</version> <configuration> <check> <totalLineRate>${cobertura.check.totalLineRate}</totalLineRate> </check> </configuration> <executions> <execution> <goals> <goal>clean</goal> <goal>check</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>${cobertura.version}</version> </plugin> ... </plugins> </reporting> </project> 

If I run mvn clean verify site , then it generates an HTML coverage report if the coverage target is met, but it does not build without generating a report if the coverage target is not fulfilled. How can I change it to always generate a report?

+4
source share
2 answers

Instead of failing to complete the assembly if the goal of code coverage is not satisfied, is it possible to set it as unstable instead? I know there are ways to do this through the Jenkins CI server, but I'm not sure if this can be done through pom.xml . Again, "unstable" assemblies may be more specific to Jenkins and may not exist as an option just through your pom file.

+4
source

Quick workaround: remove the check target:

 <executions> <execution> <goals> <goal>clean</goal> </goals> </execution> </executions> 

then run

 mvn clean verify site cobertura:check 

If you use Hudson / Jenkins, remove all checks from pom.xml and install the Cobertura plugin in Hudson and configure the checks in the Hudson / Jenkins plugin.

+1
source

Source: https://habr.com/ru/post/1379326/


All Articles