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?
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).
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.