Multimodule Project Configuration + Sonar Code Coverage Report

2,102 views
Skip to first unread message

Fagner Fernandes

unread,
May 17, 2019, 3:29:47 PM5/17/19
to JaCoCo and EclEmma Users
Hi everyone,

Even after reading Jacoco Aggregate Report I'm still struggling to configure Jacoco with Maven Multimodule configuration and send all data to Sonar (7.7). I'm using Spring Boot with Spring Cloud.

Currently, I have this structure on my application:

Parent
 - commons-module
 - eureka-module
 - module-a
 - module-b
 - module-c
 - module-d
 - module-e
 - module-f

Under build section, I'm using this configuration (jacoco.version=0.8.4):

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

And after running mvn jacoco:report-aggregate, I get this result:


ElementMissed InstructionsCov.Missed BranchesCov.
Total0 of 0n/a0 of 0n/a

So what I have done wrong?

Evgeny Mandrikov

unread,
May 17, 2019, 4:17:05 PM5/17/19
to JaCoCo and EclEmma Users
Execution of

mvn jacoco:report-aggregate

above documentation states:

The report is created from all modules this project depends on. From those projects class and source files as well as JaCoCo execution data files will be collected.

What refers to "dependencies" section of pom.xml
Unlikely that your "Parent" specifies "dependencies", so "target/site/jacoco-aggregate/" is empty as expected.
If your "module-a" for example has "commons-module" in its dependencies, then expect that "module-a/target/site/jacoco-aggregate" is not empty.

"report-aggregate" is not intended to be triggered from command-line, but to be declared in a dedicated module and bound to same phase - for example
or
or

Fagner Fernandes

unread,
May 20, 2019, 7:38:47 AM5/20/19
to JaCoCo and EclEmma Users
Evgeny,

Thanks for your reply, it helped me a lot.

So I needed to add my modules in my parent project as dependencies so this way report-aggregate can invoke jacoco.exe in each module and append on a single site, right?

But if I need to excludes some classes from Jacoco's analysis I need to declare theses exclusions on my parent's pom or each one of my modules?

Thanks again in advance.

Evgeny Mandrikov

unread,
May 20, 2019, 8:03:52 AM5/20/19
to JaCoCo and EclEmma Users


On Monday, May 20, 2019 at 1:38:47 PM UTC+2, Fagner Fernandes wrote:
Evgeny,

Thanks for your reply, it helped me a lot.

So I needed to add my modules in my parent project as dependencies so this way report-aggregate can invoke jacoco.exe in each module and append on a single site, right?


Have you tried to look at any of the provided examples??
Parent is not touched in all of them,
instead they all have a dedicated module for generation of aggregated coverage report,
where report-aggregate is bound to some phase such as "package"
and so will be executed during execution of "mvn package" or "mvn verify".

And this is exactly what was already advised in my previous email:

"report-aggregate" is not intended to be triggered from command-line, but to be declared in a dedicated module and bound to same phase

Because dependency of parent on its children looks incredibly weird, not even sure that it works.


But if I need to excludes some classes from Jacoco's analysis I need to declare theses exclusions on my parent's pom or each one of my modules?


If you want to exclude classes from being shown in report generated by "report-aggregate", then in the configuration for "report-aggregate" - https://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html#excludes

If you want to exclude classes from being shown in report generated by "report", then in the configuration for "report" - https://www.jacoco.org/jacoco/trunk/doc/report-mojo.html#excludes

Fagner Fernandes

unread,
May 20, 2019, 10:16:28 AM5/20/19
to JaCoCo and EclEmma Users
Yes, I looked at examples you told me earlier but not deeply (time constraint is real pain sometimes).

Sorry, I took the wrong approach to solve my problem because when I looked at this example (https://github.com/jacoco/jacoco/blob/v0.8.4/jacoco-maven-plugin.test/it/it-report-aggregate/report/pom.xml#L25-L62) I saw this pom's file as a parent instead of dedicated testing module.

In my defense I tried to solve this way since when Jenkins triggers the build, it executes jacoco from maven plugin command line (i,e,: mvn clean package jacoco:report-aggregate sonar:sonar) and sends reports to Sonar.

And dependency on parent it's really weird since it's other way around.

I'll refactor my project's structure and use a dedicated module test to solve all this mess.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages