For me at least, it’s often not only the test task that exists as a Test task in Gradle. For example, I often add the integrationTest task through the experimental The JVM Test Suite Plugin , and even if it’s unstable API, we have been creating test tasks before in other ways, e.g., before the new official API we used the gradle-testsets-plugin. The point is, it would be nice if the plugin allowed us an easy way to pick up the sources and binaries of every test task, not just the ones of test.
Thanks in advance.
Currently this is the workaround that I use, which seems to work well:
sonar {
properties {
val testTasks = tasks.withType<Test>().map { it.name }
property("sonar.tests", testTasks.flatMap { sourceSets[it].allSource.srcDirs }.toSet())
property(
"sonar.java.test.binaries",
testTasks.flatMap { sourceSets[it].output.classesDirs.files }.toSet()
)
property(
"sonar.java.test.libraries",
testTasks.flatMap { sourceSets[it].compileClasspath.files }.toSet()
)
property(
"sonar.junit.reportPaths",
testTasks.map {
tasks.named<Test>(it).get().reports.junitXml.outputLocation.get().asFile
})
}
}
But as you can see, it’s not ideal, it’s a lot of code and “secret” knowledge of what the plugin does for the test task.
Edit: As for code coverage reporting, you might want something like this, but I have not tested it yet (my setup is different so I didn’t need to):
property(
"sonar.coverage.jacoco.xmlReportPaths",
tasks.withType<JacocoReport>().map {
it.reports.xml.outputLocation.get().asFile
}
)