From db90e68ca7ff972cabf4f8a4d2743c444d4d30a6 Mon Sep 17 00:00:00 2001 From: abilan Date: Fri, 17 Mar 2023 09:44:23 -0400 Subject: [PATCH] Fix Sonar and JaCoCo relationship * Explicitly enable Jacoco XML report Must be `xml.required = true` * Starting with version 3 the Sonarqube Gradle plugin does not do any automatic dependencies on other tasks: https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/ * It is also does not apply the task to sub-projects. So, to make the root `sonarqube` task we need to have config like this: ``` rootProject.tasks['sonarqube'].dependsOn jacocoTestReport ``` Note: the `sonarqube` task is deprecated in favor of `sonar`, but that is exactly what our current Bamboo Sonar plugin does. So, when that is upgraded, we need to revise our config again * We don't need `xml.outputLocation` since its default is what Sonar expects --- build.gradle | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f49ba7fc28..e04e8e93c3 100644 --- a/build.gradle +++ b/build.gradle @@ -321,23 +321,22 @@ configure(javaProjects) { subproject -> compileKotlin.dependsOn updateCopyrights jacocoTestReport { + onlyIf { System.properties['sonar.host.url'] } + dependsOn test reports { - csv.required = false + xml.required = true html.required = false - xml.outputLocation = file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml") } } + rootProject.tasks['sonarqube'].dependsOn jacocoTestReport + test { maxHeapSize = '2g' jvmArgs '-XX:+HeapDumpOnOutOfMemoryError' jacoco { destinationFile = file("$buildDir/jacoco.exec") } - - if (System.properties['sonar.host.url']) { - finalizedBy jacocoTestReport - } } task testAll(type: Test, dependsOn: [':checkAsciidocLinks', 'check'])