We currently use the Gradle Sonar Runner plugin for analysing our Java multi-project source code. I would like to add a completely independent Sonar analysis covering just our unit test code (which by default is excluded from analysis with the main build), as I would like to use a different Sonar quality profile for the test code analysis.
I thought this should be a straightforward case of changing the source sets that are passed to Sonar, as specified in Section 36.5 of the Gradle documentation, but no matter how I set things up, the analysis seems only to cover the main product code. My current (broken) solution consists of the following additions to my master build.gradle file:
sonarRunner {
sonarProperties {
// Standard Sonar configuration...
...
// Remove any existing source sets
property "sonar.sources", new HashSet()
property "sonar.tests", new HashSet()
}
}
subprojects {
sonarRunner {
sonarProperties {
// Now add test source sets for each subproject to main sonar.sources
sourceSets.test.allSource.srcDirs.each { srcDir ->
def dirsThatExist = new HashSet< File >()
if ( srcDir.exists() ) {
dirsThatExist.add( srcDir )
}
properties["sonar.sources"] += dirsThatExist
}
}
}
}
The Gradle build runs, and results are pushed to Sonar. But those results stubbornly refuse to differ from the standard analysis of the production sources. What am I doing wrong?
Tom