2

I have a multi-module maven project.

parent
   child1
   child2
   child3-report

All child projects have unit tests, and child3 depends on child1 and child2. Following the pom for child3

<plugin>
     <groupId>org.jacoco</groupId>
     <artifactId>jacoco-maven-plugin</artifactId>
     <version>0.8.2</version>
     <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
                <goal>report-aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The jacoco aggregate report generated just include report for child1 and child2, but not for child3. How to fix this?

Don't want to create fourth submodule just for reports.

sidgate
  • 14,650
  • 11
  • 68
  • 119

5 Answers5

1

I've encounter the same issue when implementing Jacoco for a Maven project. Unfortunately, I'm afraid that the only solution is adding a new child module to the Maven project. You should put in it dependecies to your 3 child modules and the report-aggregate goal. So, you should have something like below configuration:

parent --> Goal: Prepare agent
   child1 --> Goal: report
   child2 --> Goal: report
   child3-report --> Goal: report
   child4-Aggregator --> Goal: report-aggregate

In your parent pom.xml, you should add child4-Aggregator module as the last module to be runned.

Omar.R
  • 91
  • 10
1

What I did is adding a report goal to include the report of the module itself.

<execution>
  <id>report-unit-tests</id>
  <goals>
    <goal>report</goal>
  </goals>
</execution>
Matt Ke
  • 3,599
  • 12
  • 30
  • 49
1

There are multiple issues raised (https://github.com/jacoco/jacoco/issues/812) on jacoco github repo related to this feature. Having separate module just for reports might be acceptable for few, but better approach would be to fix this with some configurable flag.

There is also a pending PR (https://github.com/jacoco/jacoco/pull/1007).

sidgate
  • 14,650
  • 11
  • 68
  • 119
0

The PR @sidgate mentioned is merged. Now you can configure it in maven like:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>report-aggregate</id>
            <goals>
                <goal>report-aggregate</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
                <includeCurrentProject>true</includeCurrentProject>
            </configuration>
        </execution>
    </executions>
</plugin>

Consider also the documentation.

imsandli
  • 23
  • 4
-3

maybe you can try this: add child3 itself in child3's pom.xml

<dependency>
<groupId>XXXX</groupId>
<artifactId>child3</artifactId>
</dependency>
charlyne
  • 27
  • 1
  • 2