Maven cobertura plugin - one report for multimodule project
Asked Answered
W

4

8

I'm using maven cobertura plugin to report code coverage in my multimodule project.

The problem is that I don't know how to generate one report for all modules in project.

So far I have generated separate reports for every module, but it would be nice to have one report for whole project.

My parent pom configuration:

   <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <inherited>true</inherited>
        <executions>
            <execution>
                <phase>test-compile</phase>
                <goals>
                    <goal>clean</goal>
                    <goal>cobertura</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
Whelm answered 22/9, 2010 at 10:56 Comment(0)
D
2

To my knowledge, this is currently not supported, see MCOBERTURA-65. But the issue has a patch attached, maybe try it. But my suggestion would be to use something like Sonar to aggregate metrics.

Dulci answered 22/9, 2010 at 16:8 Comment(1)
It is now supported. See my answer.Bucolic
B
18

The plugin has been updated since this question was asked (and last answered) to now enable aggregated reporting, via the aggregate configuration property in the parent POM.

This produces the aggregated coverage report at target/site/cobertura/index.html which will include all modules.

(Each module will also have it's own report produced, if that is of any use.)

Parent pom.xml

<modules>
    <module>moduleA</module>
    <module>moduleB</module>
    <module>moduleC</module>
<modules>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <check/>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            ...
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
...
</build>
Bucolic answered 23/9, 2013 at 13:19 Comment(5)
Should I run mvn cobertura:cobertura -Dcobertura.report.format=xml commmand on parent module and It will generate aggregated report in parent module?Rattlehead
I ran mvn cobertura:cobertura -Dcobertura.report.format=xml command on parent package it aggregates the reports of child modules but it do not show coverage of a class in child maven module of this parent module, if that class is covered by class from different child maven module of this parent module.Rattlehead
It sounds like you have one module testing the classes of another module. This does not sound like a good idea. A module should contain tests for its own classes. You should submit a separate question if this is not the case.Bucolic
This can also be done via without editing the pom file: mvn cobertura:cobertura -Dcobertura.aggregate=true -Dcobertura.report.format=xml You can change the report format as you wish. According to the cobertura maven plugin's github repo, this feature is available since v2.5 (commit 64a8823).Chaney
Hi, Is there a possibility to group module results in a single report ? May be under module name.Hydride
D
2

To my knowledge, this is currently not supported, see MCOBERTURA-65. But the issue has a patch attached, maybe try it. But my suggestion would be to use something like Sonar to aggregate metrics.

Dulci answered 22/9, 2010 at 16:8 Comment(1)
It is now supported. See my answer.Bucolic
J
0

I have been using Hudson as a Continuous Integration tool. The Cobertura plugin allows me to see code coverage of all of the child modules when checking on the parent.

Joannjoanna answered 19/1, 2011 at 19:50 Comment(0)
F
0

The Jenkins Cobertura plugin aggregates the report automatically but if you are interested in the coverage file itself for some other reasons you can do by following below procedure:

  1. Download Cobertura from here

  2. Go to your project workspace -> find all the .ser files and rename them

    (i=0; find . | grep cobertura.ser$ | while read line;do echo $line; cp -i $line cobertura$i.ser;i=$(($i+1));done;)
    
  3. use cobertura-merge.sh to generate global .ser file

    ~/cobertura-2.0.3/cobertura-merge.sh --datafile cobertura.ser cobertura*.ser
    
  4. use cobertura-report.sh to generate report on global .ser file

    ~/cobertura-2.0.3/cobertura-report.sh ./cobertura.ser --destination ./ --format xml
    

You will have the global coverage.xml generated in the current directory. You can use it for any kind of processing further.

Famished answered 24/8, 2013 at 0:32 Comment(1)
This can also be done via command line only using maven: mvn cobertura:cobertura -Dcobertura.aggregate=true -Dcobertura.report.format=xml You can change the report format as you wish. According to the cobertura maven plugin's github repo, this feature is available since v2.5 (commit 64a8823).Chaney

© 2022 - 2024 — McMap. All rights reserved.