Multi-module Maven Project with Jacoco

Hello,
I am working on a multi-module maven project (Java 8). I am using SonarQube 7.3.
Project Structure:
Parent
-parentpom.xml
-gitlab-ci.yaml
-Module 1
|-pom.xml
|-src
|–main
|–test
-Module 2
|-pom.xml
|-src
|–main
|–test
.
.
-Module 6
|-pom.xml
|-src
|–main
|–test

So, I am integrating jacoco reports of all the modules by adding the following to parent pom:

I have used two different approaches:
Approach 1:
I am setting sonar properties as:

<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.basedir}/…/target/jacoco.exec</sonar.jacoco.reportPaths>

Approach 2:
Setting sonar propertirs to use combined xml reports:

<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/…/target/coverage-report/coverage.xml</sonar.coverage.jacoco.xmlReportPaths>

And then I run using the following commands:
mvn test
mvn sonar:sonar

But the coverage percentage shown in Sonar does not match Jacoco coverage reports for Approach 1 and Sonar displays 0% percent coverage for Approach 2. Are such multi-module projects suppoerted by SonarQube or do we need a completely separate test module inside the parent?

Thank you for your help, in advance. :slight_smile:

hello @nishiti,

first, you are using a bit outdated version of SonarQube, if possilbe try to upgrade to the latest LTS release 7.9

You should use XML report, binary report is deprecated, so Approach 2 is way to go. Make sure that your installation has sonar-jacoco plugin to process the XML report (it is included by default it the latest versions).

See also this guide here [Coverage & Test Data] Importing JaCoCo coverage report in XML format

Hello @saberduck,

I used SonarQube 7.9 version and used sonar.coverage.jacoco.xmlReportPaths, but no progress. When I run mvn sonar:sonar, I got [DEBUG] 18:36:45.231 JaCoCo XML report found, skipping processing of binary JaCoCo exec report. in the logs. So I am assuming that it is able to find the XML reports, but it still shows the coverage as 0%. Does Sonar has any other requirement like having class files or source files in the same directory or it just uses the XML reports?

Also please take a look at my project structure:
Parent
|-parentpom.xml
|-gitlab-ci.yaml
|-target
|-Module 1
|–pom.xml
|–src
|–-main
|–-test
|–target
|—site
|----jacoco
|-----jacoco.xml
|-Module 2
|–pom.xml
|–src
|–-main
|–-test
|–target
.
.
|-Module 6
|–pom.xml
|–src
|–-main
|–-test
|–target

Just want to make sure that I don’t need all my tests to be in a separate module under the parent directory. As, all the multi-module project examples I have come across have a separate test module.

hello @nishiti ,

sorry for the delayed response. Do you have sonar-jacoco plugin installed? It is required to process the XML report.