How can I set up sonarrunner as an initscript?

Hi,

I want to set up the config for SonarQube as an init.gradle script on our CI server so that not every build.gradle needs the sonarrunner-tasks with its properties.

So I have created the following init.gradle file:

initscript {
         apply plugin: "sonar-runner"
 allprojects {
  sonarRunner {
   sonarProperties {
    property "sonar.host.url", SONARQUBE_HOST_URL
    property "sonar.jdbc.url", SONARQUBE_JDBC_URL
                                ....
                        }
       }
}

But when I try to execute it using “gradlew tasks” I get the following error:

  • What went wrong: A problem occurred evaluating initialization script. > Failed to apply plugin [id ‘sonar-runner’]

org.gradle.invocation.DefaultGradle_Decorated cannot be cast to org.gradle.api.Project

How can I set up the sonarrunner plugin in an init.gradle file on my CI-server?

The ‘initscript {…}’ closure should only be used for setting up classpath dependencies for the initialization script itself (similar to a ‘buildscript {…}’ closure). You should probably put all your logic inside the ‘allprojects {…}’ closure (to include the ‘apply plugin’ statement), if your intention is to apply a set of configuration to all projects of the build with the included init script.