Similar to SonarQube does not display detailed report per file for fully covered classes via Gradle but not a dupe.
Sonar Qube version 3.7.4 Gradle version 2.1
Running the gradle sonarRunner
generates a file test.exec which Sonar does pick up
14:50:28.167 INFO - Analysing D:\projname\build\jacoco\test.exec
14:50:28.265 INFO - No information about coverage per test.
14:50:28.266 INFO - Sensor JaCoCoSensor done: 106 ms
14:50:28.529 INFO - Execute decorators...
14:50:29.253 INFO - Store results in database
14:50:29.391 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/com.projname
However on refreshing the said project it shows coverage at 0%
Unit Tests Coverage 0.0% 0.0% line coverage 0.0% branch coverage
I have set
sonarRunner {
sonarProperties {
property 'sonar.jacoco.reportPath', 'D:\\projname\\build\\jacoco\\test.exec'
property 'sonar.junit.reportsPath','$buildDir/test-results'
property 'sonar.tests', "$buildDir/classes/test"
}
}
I have tried \ and forward slashes - it does not make a difference
any ideas?
EDIT
As per Peter's answer, removed the sonarProperties
- so build.gradle basically is
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'sonar-runner'
apply plugin: 'jacoco'
sourceCompatibility = 1.7
group = 'com.mycomp'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.10'
}
}
This does not read the default exec file which is generated at D:\projname\build\jacoco\test.exec
Instead it gives the message
17:06:36.912 INFO - Project coverage is set to 0% as no JaCoCo execution data has been dumped: D:\projname\target\jacoco.exec
Question: Does spaces in folder names cause a problem
SonarQube supports the reporting of test coverage as part of the analysis of your Java project. However, SonarQube does not generate the coverage report itself. Instead, you must set up a third-party tool to produce the report as part of your build process.
SonarQube in Action Then we'll start the SonarQube server before running the command mvn sonar:sonar. Once this command runs successfully, it will give us a link to the dashboard of our project's code coverage report: Notice that it creates a file named jacoco. exec in the target folder of the project.
Coverage per tests For Java projects using JaCoCo, it's possible to have "coverage per test" information. This includes: Displaying the number of different tests that cover a specific line.
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.
Use gradle test sonarRunner
to make sure that test and coverage results are up-to-date. Avoid absolute paths in build scripts. Groovy only performs String interpolation for double-quoted strings ("$buildDir/test-results"
). If you have the jacoco
and java
plugins applied, all the Sonar properties shown in your snippet should be preconfigured correctly.
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