How to merge jacoco coverage reports using 'merge goal' for multimodule project

4,347 views
Skip to first unread message

cbraj...@gmail.com

unread,
Apr 8, 2016, 1:53:55 PM4/8/16
to JaCoCo and EclEmma Users
Hi ,

I have a multimodule project. where i have configured jacoco for unit tests.

main
---module-a
---module-b

I have configured jacoco maven plugin in parent pom.xml

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>

</goals>
</execution>
</executions>
</plugin>


when i run mvn clean install it runs unit tests and generates .exec in each of the module. But how do i get a merged/aggregated code coverage report of the 2 modules ?

where should configure the merge goal of jacoco , in the parent pom or individual POM ?
can some body tell me how to configure the jacoco for merged report?
what configurations to set and how to run it ?

Thanks!
Raj

Marc Hoffmann

unread,
Apr 13, 2016, 2:41:24 PM4/13/16
to jac...@googlegroups.com
Hi Raj,

as of now JaCoCo Maven goals do not support multi-module reports. We
hope to have a solution ready soon
(https://github.com/jacoco/jacoco/pull/388).

In the meantime a possible workaround is to embed an Ant script in your
Maven build which supports arbitrary input sources, see JaCoCo build for
an example:
https://github.com/jacoco/jacoco/blob/master/org.jacoco.doc/pom.xml#L90

Regards,
-marc

cbraj...@gmail.com

unread,
Apr 14, 2016, 12:48:49 AM4/14/16
to JaCoCo and EclEmma Users, cbraj...@gmail.com
Thanks Marc for your reply !!

so if am not wrong the merge goal in Jacoco is useful to merge .exec files residing in same project/module and will not work with multi modules ?

when can we expect this feature to be in jacoco ?

Thanks!
Raj

Marc R. Hoffmann

unread,
Apr 14, 2016, 2:57:50 PM4/14/16
to jac...@googlegroups.com
Hi Raj,

even if this is not considered as a good practice you could probably
merge exec filed from multiple projects using relative paths.

The report-aggregate goal should be available with the next release in a
couple of weeks.

Regards,
-marc

pille...@gmail.com

unread,
Apr 18, 2016, 5:09:00 AM4/18/16
to JaCoCo and EclEmma Users, cbraj...@gmail.com
I have a working but ugly solution. The trick here is to use the Maven undocumented parameter "${session.executionRootDirectory}" to set the jacoco destFile attribute. This works pretty well, and with it, I can have only one data file shared with every modules in a multi module project, no matter how much modules you have or how deep they are nested.

Additionnaly, that parameter is not recognized by sonar-maven-plugin, but I have another hack to make it works with Sonar too (ask me if you need it)
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages