Looking at the source code, the SonarRunnerPlugin has the “recursive” behavior built-in, but the SonarRunner task does not. I’m not sure why the devs have chosen to do it like that (at least make it an option!), but I’ve been able to emulate it in a couple of ways.
First, the “sonar.sources” actually goes through each given source and its sub-directories, so you can have the custom sonar runner task analyze everything by pointing it at your top-level build directory. Here’s some code I’ve written for my sonarRunnerJS task; I exclude analysis of the external (3rd-party) libraries and the javascript created during the builds:
sonarProperties.setProperty("sonar.sources", "${projectDir}")
sonarProperties.setProperty("sonar.exclusions", "file:/${project(":common").projectDir}/externalLibraries/**/*.js, file:/${projectDir}/**/build/**/*.js")
Also, looking closely at the output from gradle --info sonarRunner I was able to determine how to specify individual subprojects through the sonar properties. Unfortunately, I’m not sure how to do this dynamically like the SonarRunnerPlugin does (so if I create a new subproject I’ll have to create new sonar properties as well). Here’s some more code I’ve written for my sonarRunnerJS task (to replace the previous block):
sonarProperties.setProperty("sonar.modules", "mySubProject")
sonarProperties.setProperty("sonar.sources", "${projectDir}/emptyDir") // It needs to point to something
sonarProperties.setProperty("mySubProject.sonar.dynamicAnalysis", "reuseReports")
sonarProperties.setProperty("mySubProject.sonar.projectBaseDir", "${project(":mySubProject").projectDir}")
sonarProperties.setProperty("mySubProject.sonar.projectName", "mySubProject")
sonarProperties.setProperty("mySubProject.sonar.projectVersion", "")
sonarProperties.setProperty("mySubProject.sonar.sources", "${project(":mySubProject").projectDir}/src/main/javascript")
Again, since this isn’t dynamic, it isn’t my preferred solution, but it works. Maybe it will be helpful to someone with a similar problem who stumbles on this thread in the future.
Thanks for all the time and help you’ve given me.
Thomas
PS: Running sonarRunner and sonarRunnerJS creates two separate projects (with the same name) in Sonar. Since this is how it works outside gradle it doesn’t concern me too much. I’ve added “sonar.branch” properties to name them differently to avoid confusion.