Java Project with multi modules

Tech Stack:

  • JDK 17;
  • Spring Boot 2.6.6
  • Maven 3.8.5
  • Gitlab Enterprise Edition 14.10.0-ee

My Java project is using multiple modules, I followed this guide here.
You can see here how my project is organized:
Screenshot 2022-07-08 at 13.33.43

Into the main pom.xml file I added it:

<build>
    <plugins>
        <plugin>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
            <groupId>org.jacoco</groupId>
            <version>0.8.8</version>
        </plugin>
    </plugins>
</build>

In the report module I added it:

<build>
    <plugins>
        <plugin>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                </execution>
            </executions>
            <groupId>org.jacoco</groupId>
            <version>0.8.8</version>
        </plugin>
    </plugins>
 </build>

The report module has the responsibility to aggregate the report just this.

When I ran ./mvnw clean verify and check under the report/target/site/jacoco-aggregate folder, I am able to check the correct report for the 3 modules:

In the main pom.xml file I added this property:

<sonar.coverage.jacoco.xmlReportPaths>
  ${project.basedir}/../report/target/site/jacoco-aggregate/jacoco.xml,
  ${project.basedir}/report/target/site/jacoco-aggregate/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>

But when I ran the pipeline into Gitlab and when I check it into SonarQube, I can see the coverage only for one module (data module):

I already checked the Gitlab log and I saw that Jacoco plugin was able to find the report;

[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=59ms

Do I miss some configuration to be able to reach my goal to see the coverage for all modules?

Hi,

Welcome to the community!

You shouldn’t need to configure the location of your JaCoCo reports; they should be picked up automatically. Can you comment that section out of your pom & try again?

 
Ann

Hi G Ann Campbell, thank you for your suggestion.

I applied it and I got it:

I checked the logs (GitLab) and I found it:

[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms

Sincerely waiting for your reply.

Hi,

Sorry. I took a look at the guide you referred to and it talks about setting your report property at the module level. So not only was I wrong about not needing to set it once, you need to set it multiple times. So not in the main pom, but in each module pom.

 
HTH,
Ann

Hi, G Ann Campbell

I have already removed the sonar.coverage.jacoco.xmlReportPaths from the main pom.xml file and added this property into the API, data, and bootstrap, but it is still the same behavior.

Kind regards,

Hi,

You’ve added it to the module poms and are still getting an error? Can you provide those analysis logs?

 
Ann