3
  • SonarQube: 8.2.0.32929
  • sonar-scanner: 3.0.3.778
  • jacoco: 0.8.4
  • jdk: 1.8
  • mvn: 3.6.3

What are you trying to achieve

I am trying to achieve code coverage by using sonar-scanner but I am getting code coverage 0 in sonarqube dashboard.

What have you tried so far to achieve this

I configured the multi-module java project using https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule

and created sonar-project.properties file in base directory with below configuration

sonar.projectKey=org.sonarqube.sonarscanner-maven-aggregate
sonar.projectName=Sonar Scanner Maven Aggregate
sonar.projectVersion=1.0
sonar.language=java
sonar.java.binaries=.

If I use mvn sonar:sonar it works. but with sonar-scanner it is not working.

It works fine with sonarqube 7.8.

Any insight would be appreciated.

saurabh landge
  • 115
  • 1
  • 2
  • 9
  • I don't know if this is related. I had to do some configuration of the jacoco plugin in the pom.xml, with the prepare-agent goal, and I think I was seeing 0 code coverage before that, but that was over a year ago, jacoco 0.8.2, and it wasn't a multi-module project. – David Conrad Apr 23 '20 at 19:04
  • I am facing it for multi module project. For single module it works fine. – saurabh landge Apr 23 '20 at 19:40

2 Answers2

2

I fixed this issue.

while running sonar-scanner command, I added the xmlReportPaths as a define property like sonar-scanner -Dsonar.coverage.jacoco.xmlReportPaths=tests/target/site/jacoco-aggregate/jacoco.xml,../tests/target/site/jacoco-aggregate/jacoco.xml

saurabh landge
  • 115
  • 1
  • 2
  • 9
0

If your projects are set up as multi-module, you will have to feed the coverage report from each module to the last module that will run as part of the build (probably integration tests modules)

https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151

https://community.sonarsource.com/t/in-sonarqube-8-2-code-coverage-is-always-showing-0/21666

https://docs.sonarqube.org/latest/analysis/coverage/

https://stackoverflow.com/a/15535970

Following the steps mentioned in this example project by Sonar team helped me https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule

As you already followed these steps, one thing I was missing was the aggregated report was not generated in the last module and I was doing it in one module before that which was our integration test module. But there was one more deployment module in our case

  • It is able to aggregate all reports from all modules into 1 module. mvn sonar:sonar goal shows coverage as well. But I want to do it with sonar-scanner which is not working. – saurabh landge Apr 24 '20 at 07:15