Tuesday, April 3, 2012

Gradle + cobertura + sonar

At my current client we use gradle for building, so i thought I should give sonar+cobertura a go. Here is my config.
subprojects {
    apply plugin: 'java'
    apply plugin: 'sonar'

    // add support for the cobertura task 
    def coberturaPluginBase = 'https://raw.github.com/valkolovos/gradle_cobertura/master/ivy'
    apply from: "${coberturaPluginBase}/gradle_cobertura/gradle_cobertura/1.0-rc4/coberturainit.gradle"

    // configure sonar to pick up the cobertura test-reports
    sonar {
        project {
            coberturaReportPath = file('build/reports/cobertura/coverage.xml')
        }
    }
}
Now you can run cobertura and sonar with the command:
 # gradle cobertura sonarAnalyze

You do need a running instance of sonar to make use of this. Download it here and configure the plugin like this.

Sources:
Sonar-plugin(1.0-m08)
http://gradle.org/docs/current/userguide/sonar_plugin.html
Cobertura-plugin(1.0-rc4)
https://github.com/valkolovos/gradle_cobertura

No comments:

Post a Comment