SonarQube - Community Edition Version 7.9.6
I am trying to get code coverage reported in SonarQube for a multi module Gradle project. I can generate the xml coverage report locally but it is not published to SonarQube when running a Jenkins build. Here is the root build.gradle file:
plugins {
id 'java'
id 'jacoco'
id 'org.sonarqube' version '3.2.0'
}
group 'org.misoenergy.mect'
version '1.0'
allprojects {
group 'org.misoenergy.mect.services'
repositories {
maven {
url 'https://nexus.misoenergy.org/repository/public/'
}
mavenCentral()
}
}
subprojects {
apply plugin: 'org.sonarqube'
apply plugin: 'java'
sonarqube {
properties {
property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
property 'sonar.projectName', 'MECT Services'
property 'sonar.projectKey', 'mect.mect-services'
}
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
}
task buildAllServices {
dependsOn ':wsdx-service:build'
dependsOn ':settlements-service:build'
}
tasks.register("codeCoverageReport", JacocoReport) {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects { subproject ->
subproject.plugins.withType(JacocoPlugin).configureEach {
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
//the jacoco extension may be disabled for some projects
if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) {
sourceSets subproject.sourceSets.main
executionData(testTask)
} else {
logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. ' +
'This test task will be excluded from jacoco report.',
testTask.getName(),subproject.getName())
}
}
// To automatically run `test` every time `./gradlew codeCoverageReport` is called
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
rootProject.tasks.codeCoverageReport.dependsOn(it)
}
}
}
reports {
// for tooling
xml.enabled true
// for humans
html.enabled true
}
}
tasks.withType(Test).configureEach {
finalizedBy codeCoverageReport
}
Any help is greatly appreciated. Please let me know if I can provide additional information.