How to set project GroupId via Sonar plugin?

I believe the basic thing I need to know is, how can I set the project GroupId via the Sonar plugin?

Detail: I’m using Gradle 1.0-M3 and Sonar IDE for Eclipse 2.2. I can successfully run a Sonar analysis from Gradle. It appears in Sonar with key = “:MyProject”. Note the empty GroupId (before the colon). When I attempt to configure MyProject to use the Sonar IDE for Eclipse, I get an error message “empty GroupID for project MyProject”. Thus I believe I need to set a non-empty GroupId in the Sonar plugin for Gradle.

Any suggestions?

The simplest way is to set project.group. Alternatively, you can set the whole key with sonar.projectKey.

Thanks, Peter. Adding the following line to build.gradle worked.

project.group='MyGroup'

I’m getting a different error now, but I believe it has nothing to do with Gradle!

FYI, the Sonar plugin has been completely redesigned/rewritten for the upcoming M5. Among other things, it’s now faster and can handle larger multi-project builds.

Where exactly does project.group or sonar.projectKey go in build.gradle?

My build.gradle looks like this (with other stuff removed):

apply plugin: ‘sonar’

sonar {

server {

url = System.getProperty(“sonar.host.url”) ?: “http://servername:80/sonar

}

database {

url = System.getProperty(“sonar.jdbc.url”) ?: “jdbc:mysql://servername:3306/sonar?useUnicode=true&characterEncoding=utf8”

driverClassName = System.getProperty(“sonar.jdbc.driver”) ?: “com.mysql.jdbc.Driver”

username = System.getProperty(“sonar.jdbc.username”) ?: “sonar”

password = System.getProperty(“sonar.jdbc.password”) ?: “sonar”

}

}

No matter where I put the line:

sonar.projectKey=‘com.company.team:team-product’

The project key shows up in Sonar as ‘trunk:team-product’.

I had a single-project build, and I set project.group at the “top-level” of the script. It is not inside of a configuration block or task definition. The same level at which you apply a plugin or set sourceCompatibility, for example.

I have a multi-project build but am starting out just running sonar on one subproject. I started trying to set project.group=“com.company.team” at the top of the subproject’s build.gradle outside of any blocks, but that didn’t work either.

I got it by setting properties inside the project block:

sonar {

server {

url = System.getProperty(“sonar.host.url”) ?: “http://servername:80/sonar

}

database {

url = System.getProperty(“sonar.jdbc.url”) ?: “jdbc:mysql://servername:3306/sonar?useUnicode=true&characterEncoding=utf8”

driverClassName = System.getProperty(“sonar.jdbc.driver”) ?: “com.mysql.jdbc.Driver”

username = System.getProperty(“sonar.jdbc.username”) ?: “sonar”

password = System.getProperty(“sonar.jdbc.password”) ?: “sonar”

}

project {

key=“com.company.team:project”

name=“full project name”

withProjectProperties { props ->

props[“sonar.core.codeCoveragePlugin”] = “clover”

}

}

}

If you set the Gradle project’s name and group, you should get decent defaults for the Sonar project’s key and name. Unsure why this wouldn’t work for you. Alternatively, you can set key and name explicitly like you did.

We have an existing Sonar server with these projects set up and I’m trying to match the key/name exactly. We’re switching from standard Ant to Gradle so I’m just trying to work out the kinks so it’s as close to our existing build as possible.

That’s fine. I’m just saying that I don’t understand why setting project.group didn’t work for you (if that’s supposed to mean “had no effect whatsoever”).

That’s fine. I’m just saying that I don’t understand why setting project.group didn’t work for you (if that’s supposed to mean “had no effect whatsoever”).