3

I have a multi-module maven project. I am facing issues while generating the sonar report for the jacoco report-aggregate coverage.

I have 2 modules (A and B) for which I want to generate the report. I have created another module (jacoco-report-aggr) under the parent module for generating the report-aggregate of jacoco.

When I run "mvn clean install", the jacoco index.html fille generated in the jacoco-report-aggr module shows the coverage for both modules A and modules B. But when I run "mvn sonar:sonar" the sonar report generated shows the coverage for only module B but not module A. Attaching the corresponding parts of the xml files.

I have the parent pom.xml as below.

<sonar.java.coveragePlugin>jacoco-maven-plugin</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.language>java</sonar.language>
        <jacoco.version>0.8.5</jacoco.version>
        <surefire.plugin.version>2.19.1</surefire.plugin.version>
        <aggregate.report.dir>jacoco-report-aggr/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
        <sonar.coverage.jacoco.xmlReportPaths>/jacoco-report-aggr/target/site/jacoco/jacoco.xml,/jacoco-report-aggr/target/site/jacoco-aggregate/jacoco.xml,
            ${basedir}/../${aggregate.report.dir},
            ${basedir}/../../${aggregate.report.dir},
            ${basedir}/../../${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>




            <!--Jacoco Code Coverage Plugin. Only start the agent-->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacoco.agent.argLine</propertyName>
                            <destFile>target/jacoco.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
                <!--Maven Surefire Plugin-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${surefire.plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.7.0.1746</version>
                </plugin>

The child modules pom looks like this.

 <properties>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/../${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

The pom.xml file of the jacoco-report-aggr module looked like this

<dependencies>
      <dependency>"Module A"</dependency>
      <dependency>"Module B"</dependency>
</dependencies>

  <properties>
    <sonar.coverage.jacoco.xmlReportPaths>${basedir}/../${aggregate.report.dir} 
    </sonar.coverage.jacoco.xmlReportPaths>
  </properties>


  <build>
    <plugins>
      <!--Maven Surefire Plugin-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire.plugin.version}</version>
      </plugin>
      <!--Jacoco Aggregate Report plugin over dependencies-->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <executions>
          <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

0 Answers0