javamavenjunitjacocojunit-jupiter

JaCoCo report doesn't include classes from all dependencies


I have a multimodule Maven project. Root pom.xml looks like following:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.11</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<modules>
    <module>...</module>
    <module>mytests</module>
</modules>

The pom.xml file from mytest module looks like this one:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.11</version>
            <executions>
                <execution>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>a.b.company</groupId>
        <artifactId>my.company.services</artifactId>
    </dependency>
</dependencies>

Obviously, the dependency my.company.services has other dependencies.

But when I execute from the root project the command mvn test jacoco:report-aggregate, the report only includes the classes from my.company.services module. Do not include the rest of dependencies.

Any idea about how to tell jacoco to include classes from all the dependencies?


Solution

  • The modules that are added as dependencies in the mytest module will be used in the jacoco reports. So if you require coverage reports for other modules, add them to the dependency list there.