Maven cobertura plugin - one report for multimodule project

Lukasz Moren picture Lukasz Moren · Sep 22, 2010 · Viewed 9.3k times · Source

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>

Answer

vegemite4me picture vegemite4me · Sep 23, 2013

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>