Question

I'm trying to convert my configuration from the old gradle 'sonar' plugin to the new gradle 'sonar-runner' plugin for gradle 1.5.

Since I switched to the sonar-runner plugin, sonar is no longer reusing my cobertura coverage.xml to calculate unit test coverage. I can't find any examples in the sonar-runner user guide showing how to configure this. Previously I was using the sonar.project.coberturaReportPath to specify the location of my coverage.xml.

My sonar instance is v.3.4. I'm using a gradle cobertura plugin to generate my coverage.xml.

Here's my sonar-runner configuration:

sonarRunner {
    sonarProperties{
        property "sonar.host.url", "http://sonar"
        property "sonar.jdbc.url", "jdbc:mysql://sonar:3306/sonar"
        property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
        property "sonar.username", "username"
        property "sonar.password", "password"
        property "sonar.language", "grvy"
        property "sonar.coberturaReportPath", file("$buildDir/reports/cobertura/coverage.xml") //not sure if this is right!
    }
}

Here's my old sonar configuration (which worked!):

sonar {
    server {
        url = "http://sonar"
    }
    database {
        url = "jdbc:mysql://sonar:3306/sonar"
        driverClassName = "com.mysql.jdbc.Driver"
        username = "username"
        password = "password"
    }
    project {
        language = "grvy"
        coberturaReportPath = file("$buildDir/reports/cobertura/coverage.xml")
    }
}
Was it helpful?

Solution

You have to make sure to use the correct Sonar properties. From http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project:

sonarRunner {
    ...
    sonarProperty "sonar.java.coveragePlugin", "cobertura"
    sonarProperty "sonar.cobertura.reportPath", file(...)
}

OTHER TIPS

I was using:

and I could not get it work. Sonar was displaying the "-" instead of the percentage of covered code.

I found this JIRA which should be fixed in Sonar Groovy Plugin 1.0, if you have the same problem as I had and that the 1.0 is released already, an update may fix the problem.

Or else, there is a workaround discussed in this topic:

  • Download the Spantree fork of the Sonar Groovy Plugin
  • Unzip and build (mvn install in the root of the sonar-groovy-master project)
  • Copy sonar-groovy-plugin-1.0-spantree-SNAPSHOT.jar in the extensions/plugins subdirectory of your Sonar installation directory
  • Remove or alter the extension of the old sonar-groovy-plugin-0.6.jar
  • Restart sonar and try gradle sonarRunner again
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top