Must-share information (formatted with Markdown):
-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
We are using Enterprise EditionVersion 8.9.5 (build 50698) -
what are you trying to achieve
We are trying to get pull-request analysis code coverage information from SonarQube.
We have a multi-module Gradle project and run the Sonar task from Gradle. We run the Sonar task from Gradle in Jenkins runs.
Sonar task ran successfully and is able to post analysis on our On-prem Sonarqube Enterprise server. But coverage information is missing. -
what have you tried so far to achieve this
Here is our project structure
Root of the project
├── build.gradle.kts
├── MakeFile
├── matcher-domain (module)
│ ├── src
│ └── build.gradle.kts
└── matcher-service (module)
├── src
└── build.gradle.kts
In root build.gradle.kts, we have following definition
sonarqube {
properties {
property("sonar.sourceEncoding", "UTF-8")
property("sonar.projectName", "matcher")
property("sonar.projectKey", "matcher")
property(
"sonar.coverage.jacoco.xmlReportPaths",
"$projectDir/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
)
}
}
subprojects {
apply(plugin = "org.sonarqube")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
sonarqube {
properties {
property("sonar.sources", "src/main")
property("sonar.tests", "src/test")
property(
"sonar.coverage.jacoco.xmlReportPaths",
"$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
)
}
}
}
In matcher-domain/build.gradle.kts
tasks.test {
dependsOn(tasks.ktlintCheck)
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required.set(true)
}
}
In matcher-service/build.gradle.kts
tasks.test {
dependsOn(tasks.ktlintCheck)
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required.set(true)
}
}
We run the Gradle command in Makefile with the following options
These variables are available in the Jenkins Job
./gradlew clean check sonarqube --debug -Dsonar.language=kotlin \
-Dsonar.host.url=${SONAR_HOST_URL} \
-Dsonar.login=${SONAR_LOGIN} \
-Dsonar.pullrequest.key=${PR_ID} \
-Dsonar.pullrequest.branch=${PR_BRANCH} \
-Dsonar.pullrequest.base=master \
-Dsonar.scm.provider=git
Jenkins build run logs are attached here.
sonarqube-no-coverage-log.txt (49.3 KB)
Can anyone help us here?