I think it is the same issue. The problem isn’t in running the plugin @cammyjoe, but the fact that sonar’s plugin defers to the allprojects
block. I didn’t update my post with a working solution, because I’m not looking for a working solution (I have a working solution, it’s just messy), I wanted to ask if sonar could change the design of their plugin to avoid the workaround. Like you, I also had solutions that seemed to do nothing.
For reference, here is the working solution (in kotlin)
class SonarPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
if (!pluginManager.hasPlugin("org.sonarqube")) {
pluginManager.apply("org.sonarqube")
}
tasks {
withType<SonarQubeTask> {
project.allprojects {
extensions.configure<SonarQubeExtension>() {
if (project.hasProperty("sonar-test")) {
properties {
property("sonar.sources", "src/test")
property("sonar.tests", "")
property("sonar.coverage.exclusions", "src/**/*")
property("sonar.projectName", "${project.description} Tests")
property("sonar.projectKey", "${project.group}.server:${project.name}-tests")
}
} else {
properties {
property("sonar.projectName", "${project.description}")
property("sonar.projectKey", "${project.group}.server:${project.name}")
}
}
}
}
}
}
}
}
Note that I have to defer the property setup using the project.allprojects {
block, because you are forced to wait until after sonar has configured the allprojects
block before you can set the properties.