How to set project GroupId via Sonar plugin?


(Dan Stine) #1

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?


(Peter Niederwieser) #2

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


(Dan Stine) #3

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!


(Peter Niederwieser) #4

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.


(dave.novelli) #5

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’.


(Dan Stine) #6

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.


(dave.novelli) #7

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.


(dave.novelli) #8

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”

}

}

}


(Peter Niederwieser) #9

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.


(dave.novelli) #10

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.


(Peter Niederwieser) #11

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”).


(Peter Niederwieser) #12

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”).