Why cobertura reports code coverage as zero for all but one module in multi-module maven project?
Asked Answered
T

1

0

I am trying to generate code coverage report for our multi-module maven project using cobertura. After I run mvn clean and then run mvn package. Then, in one of the modules from where we run JUnit tests, the coverage report generated for that module is correct as expected. But the coverage is only for a few packages. Not all packages are covered. Remember it is a multi-module project with one parent POM and each child module having its own POM. Should I also include the cobertura maven plugin details in each of those child POMs ?

However, the individual module specific coverage report generated in the other /target/site/cobertura directories is reported as zero for both line coverage and branch coverage.

Am I missing something, in my parent POM ?, I have not made any changes to any of the child POMs in the directories. Please let me know how to generate the code coverage report for a multi module maven project using cobertura.

Here is how my parent POM looks like.

<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>
    <inherited>true</inherited>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>cobertura</goal>
            </goals>
       </execution>
   </executions>
</plugin>

...

<dependencies>
    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.5.1</version>
        <type>plugin</type>
        <scope>package</scope>
    </dependency>
</dependencies>

Thanks!

Thetisa answered 30/6, 2012 at 7:22 Comment(1)
Which jdk version are you using/specifing in your maven-compiler-plugin config section?Tolson
P
2

According to the docs, there's a distinction between plugins that run as part of the build and plugins that run as part of reporting : http://maven.apache.org/guides/mini/guide-configuring-plugins.html

your using 'executions' suggests that you have the plugin under 'build' whereas apparently it belongs under 'reporting' - as per the cobertura usage page : http://mojo.codehaus.org/cobertura-maven-plugin/usage.html

Try removing cobertura plugin completely from 'build', and instead putting it under 'reporting' :

<project>
    <!-- project stuff-->
    <build>
        <!-- build stuff -->
    </build>
    <reporting>
        <plugins>
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.2</version>
                <configuration>
                    <formats>
                        <format>html</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

then run it either with

mvn cobertura:cobertura

or with

mvn site
Polyethylene answered 2/7, 2013 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.