Code coverage not reflecting in SonarQube UI

I am trying to establish a static code analysis using SonarQube. Created a project in SonarQube UI. Ran the sonarscanner within Jenkins pipeline.

The pipeline ran successfully and the report was published to SonarQube but it is not showing the code coverage as expected :


It shows that the tests were found but still shows the coverage to be 0%.

I have used jacoco plugin in my pom.xml :


I am running jacoco:prepare-agent and jacoco:report inside my pipeline. Even tried to run mvn clean install prior to running the jacoco goals but no use.

Also check the xml file generated under target/surefire-reports which shows the tests were run :

Test set: in.javahome.myweb.controller.CalculatorTest

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec

SonarQube version : 7.9.4
Jenkins version : 2.259

Any pointers as where the issue might be would be much appreciated.



This guide might help: