Sam
Sam

Reputation: 311

Analysing sonar with gradle

we are pretty much impressed with working of sonarqube with Java projects and planning to go for next level by analyzing Android projects. we have Sonarqube version-5.6.6 and gradle-2.8. Below is my configuration added for our android projects build.gradle.

 dependencies {
    classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1"
  }
  
  sonar {
    server {
        url = "http:sonar-url.com"
    }
 }

apply plugin: "sonar"

this is issue popping up when I run gradle sonar

Could not find method sonar() for arguments [build_2gg1yf48v6l7ngh099813mf0i$_run_closure1$_closure4@61d34b4] on root project 'project name'.

Upvotes: 0

Views: 10929

Answers (1)

Simon Schrottner
Simon Schrottner

Reputation: 4754

Hi i am curious why you decided to use an outdated plugin version, when you just start your gradle implementation. At SonarQube Gradle Plugin Doc you find a detailed description how to actually use it.

Generally speaking for the new Gradle version, you need to:

  • change the classpath
  • change the task
  • change the configuration

eg.

dependencies {
    classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5'
}

apply plugin: 'org.sonarqube'

sonarqube {
  properties {
    property "sonar.host.url", "http://sonarserver.com"
  }
}

and you run it with:

gradle sonarqube

Additional notes:

  • you do not need to put the sonar url in your gradle script at all. You could simply use a sonar-project.properties file in the directory where you are running the gradle task. in this case all your settings are easily reusable for different runners.
  • you are maybe not able to set the property with property "sonar.host.url", "http://sonarserver.com". In my project i strangly set just this property with System.setProperty("sonar.host.url", "<sonar-url>"). I do not know why, but i am sure there is a reason for that, and i want to let you know this.

Upvotes: 4

Related Questions