6

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

Community
  • 1
  • 1
shinynewbike
  • 2,334
  • 5
  • 28
  • 42

1 Answers1

3

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.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • I tried that - please see update. Question: Does spaces in folder names cause a problem – shinynewbike Nov 11 '14 at 11:41
  • You need to run `gradle test sonarRunner`. The `sonarRunner` plugin must be applied to the root project only, not to subprojects (as explained in the SonarRunner plugin chapter in the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html)). You can also try with your manual `sonarRunner` configuration, but you'll need to fix `'$buildDir/test-results'` (needs double quotes) and should replace the absolute path with `project.file("relative/path")`. I doubt that spaces will cause problems, but you can always try to rename the affected folders. – Peter Niederwieser Nov 11 '14 at 11:52
  • Thank you. This seems very relevant "The sonarRunner plugin must be applied to the root project only, not to subprojects (as explained in the SonarRunner plugin chapter in the Gradle User Guide)" I will try this out and revert – shinynewbike Nov 11 '14 at 12:13