Still confused about how to set up jacoco in multimodule project

11,441 views
Skip to first unread message

David Karr

unread,
Jan 19, 2017, 7:14:13 PM1/19/17
to JaCoCo and EclEmma Users
I'm about to set up our medium-size maven multiproject build to use jacoco for its unit tests.  Despite the documentation and some similar questions on the net, I still don't understand exactly how to set this up.

I have a parent pom that code modules have as their parent, and I have a separate aggregator pom that lists the modules to build.

My goal is to generate the jacoco data file in each child module, and initially use "report-aggregate" to generate a view of the aggregated data, and then later integrate with SonarQube.

I assume I would put the relevant jacoco settings in the parent pom and aggregator pom.  The former for the "prepare-agent" settings for each child module, and the latter for the "report-aggregate".

The following are my changes to the parent pom.  I added the reference to the jacoco plugin, and added the one "argLine" setting to the surefire configuration:
<plugins>
   
<plugin>
       
<groupId>org.jacoco</groupId>
       
<artifactId>jacoco-maven-plugin</artifactId>
       
<version>0.7.8</version>
       
<executions>
           
<execution>
               
<id>default-prepare-agent</id>
               
<goals>
                   
<goal>prepare-agent</goal>
               
</goals>
               
<configuration>
                   
<propertyName>jacoco.agent.ut.arg</propertyName>
               
</configuration>
           
</execution>
       
</executions>
   
</plugin>
   
<plugin>
       
<groupId>org.apache.maven.plugins</groupId>
       
<artifactId>maven-surefire-plugin</artifactId>
       
<version>2.19.1</version>
       
<configuration>
           
<forkCount>3</forkCount>
           
<aggregate>true</aggregate>
           
<reuseForks>true</reuseForks>
           
<argLine>@{jacoco.agent.ut.arg} -Xmx1024m -XX:MaxPermSize=256m</argLine>
           
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
           
<includes>
               
<include>**/*Test.java</include>
           
</includes>
       
</configuration>
   
</plugin>
    ...
</plugins>

When I run the build, I see in the build for each child module lines like the following:
[INFO] --- jacoco-maven-plugin:0.7.8:prepare-agent (default-prepare-agent) @ usl-parent-pom ---
[INFO] jacoco.agent.ut.arg set to -javaagent:...\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.8\\org.jacoco.agent-0.7.8-runtime.jar=destfile=...\\usl-parent-pom\\target\\jacoco.exec


I also added the following to the aggregator pom:
    </modules>
   
<build>
       
<plugins>
           
<plugin>
               
<groupId>org.jacoco</groupId>
               
<artifactId>jacoco-maven-plugin</artifactId>
               
<version>0.7.8</version>
               
<executions>
                   
<execution>
                       
<id>report-aggregate</id>
                       
<goals>
                           
<goal>report-aggregate</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
       
</plugins>
   
</build>

When I ran the build, I found that it generated the "jacoco.exec" files in the "target" directory of child modules, but it looks like that's all that it did.  I didn't see an aggregated report built.

I then manually ran "mvn jacoco:report-aggregate" from the top level, and it seemed to do some work, and it generated an html tree, but when I viewed it in the browser, I saw that it didn't actually find any data.  It showed an empty table, like this:
ElementMissed InstructionsCov.Missed BranchesCov.
Total0 of 0n/a0 of 0n/a

I'm probably missing multiple important details here.  What can I do here?

Evgeny Mandrikov

unread,
Jan 21, 2017, 9:37:14 AM1/21/17
to JaCoCo and EclEmma Users
Hi,

As stated in http://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html "report-aggregate" uses dependencies to build report, so requires a dedicated module and not aggregator pom.

You can find an example in integration tests for JaCoCo Maven Plugin - see https://github.com/jacoco/jacoco/tree/v0.7.8/jacoco-maven-plugin.test/it/it-report-aggregate

Also build of JaCoCo itself utilizes this feature - see https://github.com/jacoco/jacoco/blob/0.7.8/org.jacoco.doc/pom.xml#L111-L135

And you can find other examples in internet, e.g. https://groups.google.com/d/msg/jacoco/mfRi97alxqs/63KqpEZKAQAJ

Hope this clarifies,
Evgeny

David Karr

unread,
Jan 22, 2017, 3:27:33 PM1/22/17
to JaCoCo and EclEmma Users

Yup, that looks reasonable.  I haven't implemented it yet, but I'm optimistic.

David Karr

unread,
Jan 30, 2017, 6:19:50 PM1/30/17
to JaCoCo and EclEmma Users
On Saturday, January 21, 2017 at 6:37:14 AM UTC-8, Evgeny Mandrikov wrote:

I need more information. It generated the report, but it showed no coverage.  I'm guessing I have to somehow communicate the name of the ".exec" file that I'm using.

I constructed an additional module called "jacoco-aggregate", and this is an excerpt of its POM:
    <dependencies>
       ...
   
</dependencies>

   
<build>
       
<plugins>
           
<plugin>
               
<groupId>org.jacoco</groupId>
               
<artifactId>jacoco-maven-plugin</artifactId>
               
<version>0.7.8</version>
               
<executions>
                   
<execution>
                       
<id>report-aggregate</id>

                       
<phase>verify</phase>

                       
<goals>
                           
<goal>report-aggregate</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
       
</plugins>
   
</build>
</project>

I added a dependency for each child module that has unit tests.  I verified that those individual modules are generating data. I looked at the properties for report-aggregate, but it's not obvious how I configure it to know what the name is of the data file in each module.
 

David Karr

unread,
Jan 30, 2017, 6:36:49 PM1/30/17
to JaCoCo and EclEmma Users
On Saturday, January 21, 2017 at 6:37:14 AM UTC-8, Evgeny Mandrikov wrote:

And thinking more about this, if I simply specify child project dependencies, how can "report-aggregate" even know where the datafile is for each child project?  Does it expect that the datafile would have been installed as an artifact?  That seems hard to believe.

Evgeny Mandrikov

unread,
Jan 30, 2017, 6:57:26 PM1/30/17
to JaCoCo and EclEmma Users
"report-aggregate" searches exec files relatively to location of dependencies within current Maven reactor using "dataFileIncludes" and "dataFileExcludes" - see http://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html#dataFileIncludes


And in addition to examples that were provided before - http://stackoverflow.com/a/41901853/244993 full working example (not just excerpt from pom) that uses "dataFileIncludes".

Hope this helps,
Evgney

On Tuesday, January 31, 2017 at 12:19:50 AM UTC+1, David Karr wrote:
I need more information. It generated the report, but it showed no coverage.  I'm guessing I have to somehow communicate the name of the ".exec" file that I'm using.

I constructed an additional module called "jacoco-aggregate", and this is an excerpt of its POM: 
 
I added a dependency for each child module that has unit tests.  I verified that those individual modules are generating data. I looked at the properties for report-aggregate, but it's not obvious how I configure it to know what the name is of the data file in each module.
 
 

David Karr

unread,
Jan 30, 2017, 7:28:16 PM1/30/17
to JaCoCo and EclEmma Users
On Monday, January 30, 2017 at 3:57:26 PM UTC-8, Evgeny Mandrikov wrote:
"report-aggregate" searches exec files relatively to location of dependencies within current Maven reactor using "dataFileIncludes" and "dataFileExcludes" - see http://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html#dataFileIncludes


And in addition to examples that were provided before - http://stackoverflow.com/a/41901853/244993 full working example (not just excerpt from pom) that uses "dataFileIncludes".

Hope this helps,
Evgney

I still can't get it to find the "coverage.exec" files from my child modules.

This is a new excerpt from the "jacoco-aggregate" pom, which is a peer child module to the modules with unit tests:
    <dependencies>
       
<dependency>
           
<groupId>com.att.detsusl</groupId>
           
<artifactId>usl-account-impl</artifactId>
           
<version>2.3.0-SNAPSHOT</version>
       
</dependency>
       ...
   
</dependencies>

   
<build>
       
<plugins>
           
<plugin>
               
<groupId>org.jacoco</groupId>
               
<artifactId>jacoco-maven-plugin</artifactId>
               
<version>0.7.8</version>
               
<executions>
                   
<execution>
                       
<id>report-aggregate</id>

                       
<phase>verify</phase>

                       
<goals>
                           
<goal>report-aggregate</goal>
                       
</goals>

                       
<configuration>
                         
<dataFileIncludes>**/target/coverage.exec</dataFileIncludes>
                       
</configuration>

                   
</execution>
               
</executions>
           
</plugin>
       
</plugins>
   
</build>
</project>


From the "jacoco-aggregate" directory, I did a "find" of "coverage.exec" files in the tree, and it includes at least "../usl-account-impl/target/coverage.exec".

I've tried different variations of the "dataFileIncludes" property, like just "target/coverage.exec".

I even tried running SysInternals "ProcMon" and watching for accesses to "coverage.exec", and it only ever saw the one it tried to create in the "jacoco-aggregate" directory.

I wish there was a way to get the process to be more verbose and describe what it's actually looking for, and finding.  I'm just poking in the dark here.
 

Evgeny Mandrikov

unread,
Jan 30, 2017, 7:58:09 PM1/30/17
to JaCoCo and EclEmma Users
I'm also in a dark, because excerpt of pom is clearly not enough to reproduce your difficulty. So could you please show full runnable example of project?

Have you tried one of examples that was given?!?
Have you tried without renaming exec files?
If you wanna continue debugging on your own without providing full example, then - use mvnDebug with a breakpoing inside plugin or custom build of plugin with additional logging.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages