I have been trying unsuccessfully for the last few days to run Cobertura 2.4 with Maven 3.0.2. We have a very large project with many modules (sub-projects). What I found is that documentation is basically non-existent or plain wrong. All tutorials I was able to find don't work with Maven 3.x (they build, but Cobertura either doesn't run or cannot generate the reports).
Has anyone here been able to make it work? Any useful tips/examples? Thanks.
I successfully integrated Cobertura in my projects with adding this:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <configuration> <instrumentation> <includes> <include>foo/bar/**/*.class</include> </includes> </instrumentation> </configuration> <executions> <execution> <id>clean</id> <phase>pre-site</phase> <goals> <goal>clean</goal> </goals> </execution> <execution> <id>instrument</id> <phase>site</phase> <goals> <goal>instrument</goal> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <!-- use mvn cobertura:cobertura to generate cobertura reports --> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> </plugins> </reporting>
If you run mvn cobertura:cobertura
the reports will be generated in target\site\cobertura
. See also maven cobertura plugin.
Today I analyze projects with SonarQube. It has an easy installation step (if you are not interested in using an enterprise database) and also includes a code coverage analysis (using JaCoCo) among many other metrics.
In maven 3.0.3 (not yet out when you asked the question), simply use maven's site plug-in and configure it such that it uses cobertura, as follows:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.0</version> <configuration> <reportPlugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> </reportPlugins> </configuration> </plugin> ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With