1
votes

I have a multimodule Maven project where the coverage reports are located in another module than the covered Java classes. An import of a not empty xml coverage report (with coverage information) into Sonarqube is successful but shows a coverage of 0.

Steps to reproduce:

  1. Checkout following github project and build it with mvn clean verify. After that there exist an aggregated xml report located in coverage/target/site/jacoco-aggregate-all/jacoco.xml. You can see coverage data in there and also in the corresponding html-Report.

coverage report

  1. Start sonarqube (current version 8.4.1) with following command and wait a little bit.
docker run -d -p 9000:9000 sonarqube

edit: Plugin "JaCoco xml report importer" is already installed in this image.

JaCoco xml report importer is installed

  1. Publish coverage data with following (verbose) command. Importing of report was successful (see log).
mvn sonar:sonar -X -Dsonar.projectKey=example -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-aggregate-all/jacoco.xml

## Log output contains
...
 10:54:28.519 Reading report '<project-path>\maven-multimodule-coverage\coverage\target\site\jacoco-aggregate-all\jacoco.xml'
...
  1. Browse to http://localhost:9000/dashboard?id=example. You see coverage of 0.

What am I doing wrong?

Sonar report

2

2 Answers

1
votes

It turned out that it works if I use an absolute path for the xml report file. So I added

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

to the top maven pom so each module points to the same report file. For a deeper nesting of module directories you have to introduce a property main.basedir or something.

The main understanding is that you do not provide sonar a coverage report which get mapped to the module classes, but you provide module classes which get mapped to a coverage report.

0
votes

Please install JaCoco xml report importer plugin on sonarqube instance (you will find it under marketplace just search for jacoco there). This plugin will pick up your code coverage and import it to sonarqube. so after installing plugin please use the same command to see result on sonarqube which is

mvn sonar:sonar -X -Dsonar.projectKey=example -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-aggregate-all/jacoco.xml