Migrating to sonarqube gradle plugin

Sonarqube recently released a gradle sonarqube plugin.  This replaces the sonar runner plugin provided by gradle.

Migrating to the new plugin is fairly straightforward and involves the following changes:
  • Replace
apply plugin: "sonar-runner"


with

apply plugin: "org.sonarqube"


or using the style of the new plugin mechanism (gradle 2.1 and above)

plugins {
  id "org.sonarqube" version "1.0"
}

  • Replace
sonarRunner {
    sonarProperties {
        ...
    }
}


with

sonarqube {
    properties {
    ...
    }
}

  • Move global sonarqube properties to gradle.properties - either in ~/.gradle or in your project base directory.  Use systemProp prefix to indicate system property
systemProp.sonar.host.url=http://localhost:9000
systemProp.sonar.jdbc.url=jdbc:postgresql://localhost/sonar
systemProp.sonar.jdbc.username=sonar
systemProp.sonar.jdbc.password=sonar

#if  authentication enabled
systemProp.sonar.login=admin
systemProp.sonar.password=admin


As per documentation,  the plugin uses gradle's object model to provide smart defaults for many of the standard SonarQube properties, specifically

Property - Gradle default
sonar.projectKey - “$project.group:$project.name”
sonar.projectName - project.name
sonar.projectDescription  - project.description
sonar.projectVersion - project.version


Since my gradle script did not have the above gradle defaults set, I specified the sonar properties explicitly in the properties section of the sonarqube plugin configuration. But for some reasons, they were not used and I ended up getting the project folder name as project name and project key with no description and version. The same had worked well with the sonar-runner plugin.
  • Now run
gradlew build sonarqube


or

gradle build sonarqube


(if not using the gradle wrapper)

You should see sonarqube analysis happening after the build and thereafter browse to the report.

Comments

Popular posts from this blog

Opening a safe deposit locker in SBI

Opening a Kannada Word document

Switching to Tatasky make my pack