I need to make SonarCloud import a coverage report made by JaCoCo during the build in the CI pipeline.
The coverage is done on java binaries (jar file) not on plain source files.
In the pom.xml I've put the following properties:
<sonar.sources>lib</sonar.sources>
<sonar.binaries>target/classes</sonar.binaries>
<sonar.java.binaries>target/classes</sonar.java.binaries>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.junit.reportPaths>target/coverage-reports/surefire-reports</sonar.junit.reportPaths><sonar.coverage.jacoco.xmlReportPaths>target/coverage-reports/jacoco-reports</sonar.coverage.jacoco.xmlReportPaths>
In the lib directory there is the jar file.
The JaCoCo report is created with the following setup:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/coverage-reports/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>verify</phase>
<configuration>
<dataFile>target/coverage-reports/jacoco.exec</dataFile>
<outputDirectory>target/coverage-reports/jacoco-reports</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
In the github actions .yml file I use the command:
mvn -Pcoverage verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=***
Finally, the warning I get when building the project on Github is:
Warning: No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='target/coverage-reports/jacoco-reports'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
I even tried to put the report in the default locations but, even then, no report is imported, even though it is generated locally.