5

I am trying to add an aggregated coverage report for the unit tests for a multi-module project. The coverage report is generated as expected for individual modules. But the aggregated report generated in the report module target is showing coverage as 0%

enter image description here

The structure of the modules as follows :

Root
|
|
- - - Components module
      |
      |
      - - - - - - - - - Sub module A
      |
      |
      - - - - - - - - - Sub module B
      |
      |
      - - - - - - - - - Aggregate report module

I followed this sample project: https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-report-aggregate/pom.xml

The existing root pom contains plugin config as follows, I didn't change anything there :

<plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <executions>
                        <execution>
                            <id>default-instrument</id>
                            <goals>
                                <goal>instrument</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-restore-instrumented-classes</id>
                            <goals>
                                <goal>restore-instrumented-classes</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <append>true</append>
                                <destFile>${basedir}/target/coverage-reports/jacoco-ut.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>pre-integration-test</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                            <configuration>
                                <destFile>${basedir}/target/coverage-reports/jacoco-it.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-integration-test</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/jacoco-it.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-it</outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-unit-test</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/jacoco-ut.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>merge-results</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>merge</goal>
                            </goals>
                            <configuration>
                                <fileSets>
                                    <fileSet>
                                        <directory>${basedir}/target/coverage-reports</directory>
                                        <includes>
                                            <include>*.exec</include>
                                        </includes>
                                    </fileSet>
                                </fileSets>
                                <destFile>${basedir}/target/coverage-reports/aggregate.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-merge-report</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/aggregate.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-aggregate
                                </outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>default-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/aggregate.exec</dataFile>
                                <rules>
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>INSTRUCTION</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>0.00</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.plugin.version}</version>
                    <configuration>
                        <systemPropertyVariables>
                            <jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-ut.exec
                            </jacoco-agent.destfile>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <systemPropertyVariables>
                            <jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-it.exec
                            </jacoco-agent.destfile>
                        </systemPropertyVariables>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Report aggregate module pom I added is as follows :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.wso2.carbon.apimgt</groupId>
    <artifactId>apimgt</artifactId>
    <version>6.8.148-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>report</artifactId>
  <name>Aggregate Report</name>

  <properties>
    <code.coverage.project.folder>${basedir}/../</code.coverage.project.folder>
    <code.coverage.overall.data.folder>${basedir}/../target/aggregate.exec</code.coverage.overall.data.folder>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.admin</artifactId>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.impl</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin.version}</version>
        <configuration>
          <!-- Jacoco prepare-agent builds some command-line params without -->
          <!-- which jacoco will not instrument. Hence it is important to add -->
          <!-- those command-line params here (${argLine} holds those params) -->
          <argLine>${argLine} -Xms256m -Xmx2048m</argLine>
          <forkCount>1</forkCount>
          <runOrder>random</runOrder>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
          <execution>
            <id>merge-results</id>
            <phase>verify</phase>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <directory>${basedir}/../</directory>
                  <includes>
                    <include>**/target/jacoco.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
              <destFile>${basedir}/../target/aggregate.exec</destFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

Can someone please let me know what I am doing wrong?

0 Answers0