I have a public repository where SonarCloud is invoked via Github Actions, it is a Java project that relies on Maven. SonarCloud works well, but I am unable to integrate code coverage into its reports, nor do I see coverage details in the comment generated by the sonarcloud
bot.
This is the pull request where I am experimenting with it, and this is the outcome:
Although the text says that coverage info is not available, I am sure that JaCoCo works, because if I upload the artifacts at the end of the pipeline - the files are there.
This is the relevant part of the CI pipeline:
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify sonar:sonar -Dsonar.projectKey=ralienpp_cmp-ra-component
- name: Upload artifacts for subsequent review
uses: actions/upload-artifact@master
with:
name: generated-reports
path: |
target/site
target/dependency-check-report.html
This is the sonar-related excerpt from my pom.xml
:
<sonar.organization>ralienpp</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<sonar.verbose>true</sonar.verbose>
And the jacoco
settings:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The output of the job features these lines:
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[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=71ms
It seems that the jacoco report is there, it is detected and successfully imported. Nevertheless, I still cannot figure out why SonarCloud doesn’t “see” it. What troubleshooting steps can be applied to determine the root cause of the problem?