As a follow-up to my other post, I have a CI server where I want to store the credentials for SQ & DB authentication in an init script and have that init script always run whenever there is a new build. I want to also make work for both single and multi-module builds. Here’s what the CI admin came up with:
initscript {
repositories {
maven {url 'http://repo1'}
maven {url 'http://repo2'}
}
dependencies {
classpath "org.sonarqube.gradle:gradle-sonarqube-plugin:1.1"
}
}
allprojects{
if (allprojects.size() > 1){
subprojects{
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.jdbc.username", System.getProperty('sonar.jdbc.username')
property "sonar.jdbc.password", System.getProperty('sonar.jdbc.password')
property "sonar.jdbc.url", System.getProperty('sonar.jdbc.url')
property "sonar.jdbc.driverClassName", System.getProperty('sonar.jdbc.driverClassName')
property "sonar.host.url", System.getProperty('sonar.host.url')
property "sonar.login" , System.getProperty('sonar.login')
property "sonar.password", System.getProperty('sonar.password')
}
}
}
}
else {
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.jdbc.username", System.getProperty('sonar.jdbc.username')
property "sonar.jdbc.password", System.getProperty('sonar.jdbc.password')
property "sonar.jdbc.url", System.getProperty('sonar.jdbc.url')
property "sonar.jdbc.driverClassName", System.getProperty('sonar.jdbc.driverClassName')
property "sonar.host.url", System.getProperty('sonar.host.url')
property "sonar.login" , System.getProperty('sonar.login')
property "sonar.password", System.getProperty('sonar.password')
}
}
}
}
For single module projects that run in CI and override properties like sonar.projecKey, sonar.projectName, etc. it works fine. However, in a multi-module build I was getting errors in the project build.gradle, where gradle was complaining about this:
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method sonarqube() for arguments [sonarqube_an6bhftw8aiz4ofj0bkumpfjk$runclosure2@15e4f3a] on root project 'xxxxxxx.
When I run the sonarqube task locally on my machine without using the init script, it works fine, and publishes the results of the multi-module build as expected. I have tried to put the sonarqube{} closure for adding additional properties in the allprojects section, the subprojects section and outside of either, with no luck. I am running out ideas. Thank you…