Sonarqube is not showing code coverage after running
Solution 1
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
Solution 2
I've resolved this by using the following steps:
1.To begin, I've add configuration in our pom.xml.
<properties>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
</properties>
2.In sonarqube properties file added the below part.
sonar.projectName=${JOB_NAME}
sonar.projectVersion=1.0.0
sonar.sources=src/main
sonar.sourceEncoding=UTF-8
sonar.language=java
sonar.tests=src/test
sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/jacoco.exec
sonar.binaries=target/classes
sonar.java.coveragePlugin=jacoco
sonar.verbose=true
Comments
-
Tarun Maganti over 2 years
I'm running sonarqube with maven.
I have installed it using following way. Using
brew
, I installedmysql
andsonar
.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
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
addedsonar.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?!