I'm running sonarqube with maven.
I have installed it using following way. Using brew
, I installed mysql
and sonar
.
When I run I get 7 critical bugs but the code coverage for 88 tests is zero
When I run it with IntelliJ's tools, I get the following results. (not zero!)
This is when I check Jacoco results directly. In $base_direc/target/jacoco/index.html
The same code when run with sonar-scanner
This is my maven configuration
My ~/.m2/settings.xml
Edit 1: I have found this in logs.
Edit2: I have edited ~/.m2/settings.xml
added
<properties> <sonar.host.url>http://localhost:9000/</sonar.host.url> </properties>
Edited /usr/local/Cellar/sonarqube/6.3.1/libexec/conf/sonar.properties
added sonar.host.url=http://localhost:9000/
Edited /usr/local/etc/sonar-scanner.properties
added - sonar.host.url=http://localhost:9000/
Ran the application in all above ways and the results were same, i.e, I could see Jacoco results but not in sonar.
Is it possible that if bugs are found sonar refuses to do code coverage?!
Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.
You will see how to publish code coverage to SonarQube in 2 simple steps. Enable “xml” parameter in rktracer configuration file to generate SonarQube xml file. Set reports path in sonar properties file to SonarQube xml file in project .
you can exclude all the source files in your project from coverage calculations via the UI: Administration > Analysis Scope > Coverage Exclusions. A pattern value of **/*. * ought to do it for you.
I found the solution -
The maven plugin I have included has configuration of Jacoco's destfile and datafile as ${basedir}/target/coverage-reports/jacoco-unit.exec
but by default sonar reads at ${basedir}/target/jacoco.exec
. I changed the default at http://localhost:9000/settings?category=java
Ref: Sonar Code Coverage
Couldn't find the working reference link. Here is aux link: Baeldung Sonar and jacoco
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With