Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting and Merging multi-module jacoco reports with report-aggregate

Attempting to get one jacoco report that will show all the results from multiple modules.

I am able to see that each of the sub-modules have a jacoco.exec after building the project but unsure of how to get it to output one report that will have all the results from every module combined.

This is what I have included in my Root pom.xml:

<plugin>
    <groupId>@project.groupId@</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>@project.version@</version>
</plugin>



<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I created a new module explicitly for reporting purposes. (e.g. report-aggregate-module)

Deleted the group ids and used generic artifact ids for this example:

This is what I put in the pom.xml for this report-aggregate sub-module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>report-aggregate</artifactId>
        <groupId>com.name.group</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <artifactId>report-aggregate</artifactId>
    <name>Report Aggregate</name>

    <properties>
        <wildfly.version>10.0.0.Final</wildfly.version>
        <wildfly.artifactId>wildfly-dist</wildfly.artifactId>
    </properties>

    <dependencies>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module1</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module2</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module3</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module4</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>report-aggregate</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Everything seems to compile okay, the jacoco exec doesn't seem to get created for the report-aggregate-module. Anyone know a solution to this or if I'm doing this incorrectly?

like image 335
kingz415 Avatar asked Jun 11 '18 21:06

kingz415


People also ask

What is JaCoCo report aggregate?

The JaCoCo Report Aggregation plugin (plugin id: jacoco-report-aggregation ) provides the ability to aggregate the results of multiple JaCoCo code coverage reports (potentially spanning multiple Gradle projects) into a single HTML report.

What is JaCoCo bundle?

BUNDLE: That represents the project as a whole. PACKAGE: Each java package. CLASS: As name states, a single class.

How do you exclude model classes from JaCoCo code coverage?

Starting from JaCoCo 0.8. 2, we can exclude classes and methods by annotating them with a custom annotation with the following properties: The name of the annotation should include Generated. The retention policy of annotation should be runtime or class.


1 Answers

Sorry if this comes a late answer.

I assume that your root pom.xml is an aggregater, with <modules> consisting of module1, module2, and report-aggregate. This is the cause of your trouble: as your root pom.xml is an aggregator, it runs JaCoCo BEFORE your submodules do, so your final report is empty. You should:

  • Move the configuration of goal report-aggregate of the jacoco-maven-plugin from the root POM to the report-aggregate POM. This should do the trick, because your report-aggregate POM uses <dependencies>, not <modules>.
  • Keep the configuration of goal prepare-agent of the jacoco-maven-plugin in the root POM.

I suggest you look at the JaCoCo forum https://groups.google.com/forum/#!topic/jacoco/FpdLbxsXSTY. It refers to a complete demo integration test https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate.

like image 178
Ivan dal Bosco Avatar answered Oct 19 '22 10:10

Ivan dal Bosco