Reputation: 15448
I'm using Cobertura with Maven.
I'd like the build 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 refer to the coverage report to see where they can add more coverage to fix the failed build.
Currently my pom looks like:
<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 the HTML coverage report if the coverage target is met, but it fails the build without generating the report if the coverage target is not met. How can I change it to always generate the report?
Upvotes: 4
Views: 3078
Reputation: 28845
A quick workaround: remove the check
goal:
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
then run
mvn clean verify site cobertura:check
If you are using Hudson/Jenkins remove all checks from the pom.xml
and install the Cobertura plugin to Hudson and configure the checks in the Hudson/Jenkins plugin.
Upvotes: 0
Reputation: 8100
Instead of failing the build if the code coverage target isn't met, is it possible to set it to mark the build as unstable instead? I know there are ways to do this through the Jenkins CI server, but I'm not sure if it's possible to accomplish this through pom.xml
. Then again, "unstable" builds might be more Jenkins-specific, and might not exist as a possibility only through your pom file.
Upvotes: 4