Using sonar-scanner-cli
via Docker (sonarsource/sonar-scanner-cli:4.4
).
TL;DR: How do I get JaCoCo working with sonar-scanner-cli
and not using the Gradle plugin? Am I missing system properties?
So I have a pretty minimal sonar-project.properties
file and it seems to be working quite well for my Kotlin projects. The only problem that I’m currently facing is that JaCoCo is not updating.
But seems like it’s getting imported correctly.
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=111ms
I’m aware of the Gradle plugin, but I’m hesitant to use it because I’m using a custom GitHub Action workflow to make reporting to SonarQube more general.
In any case, everything seems to be working great (PRs, branches, etc), but code coverage for JaCoCo. Even works with other languages like golang.
I’m getting the feeling that I’m missing a system property that is necessary to provide for coverage reporting that the Gradle plugin provides but not the sonar-scanner-cli
.
sonar-project.properties
:
sonar.projectKey=myproject
sonar.sources=src/
sonar.exclusions=src/test/
And part of the workflow. Should provide enough context.
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
sonar-scanner \
-D"sonar.host.url=${INPUT_SONARHOSTURL}" \
-D"sonar.scm.provider=git" \
-D"sonar.login=${INPUT_SONARTOKEN}" \
-D"sonar.pullrequest.key=${PR_KEY}" \
-D"sonar.pullrequest.branch=${GITHUB_HEAD_REF}" \
-D"sonar.pullrequest.base=${GITHUB_BASE_REF}" \
-D"sonar.pullrequest.github.repository=${GITHUB_REPOSITORY}"
elif [ "$GITHUB_EVENT_NAME" = "push" ]; then
sonar-scanner \
-D"sonar.host.url=${INPUT_SONARHOSTURL}" \
-D"sonar.projectVersion=${INPUT_GITTAG}" \
-D"sonar.scm.provider=git" \
-D"sonar.login=${INPUT_SONARTOKEN}" \
-D"sonar.branch.name=${_branch_name}"
fi