Hi all;
I can see this is asked multiple times but I wasn’t able to find a solution to this still. I followed the guideline here and set up the project accordingly but coverage somehow is not being reported.
Some Basic Details:
I checked coverage in my local and its properly generated:
Basic Project Info:
- Language: Java 21 with maven
- CI System Used: GitHub actions
- SonarQubeCloud (aka sonarcloud)
Details or Troubleshooting:
1) pom.xml
-
related properties:
<junit.version>4.11</junit.version> <jacoco.version>0.8.12</jacoco.version> <sonar.organization>*****</sonar.organization> <sonar.projectKey>>*****</</sonar.projectKey> <sonar.host.url>https://sonarcloud.io</sonar.host.url> <sonar.language>java</sonar.language> <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> <sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths> <sonar.verbose>true</sonar.verbose> <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding> <sonar.sources>src/main/java</sonar.sources> <sonar.tests>src/test/java</sonar.tests> <sonar.java.binaries>target/classes</sonar.java.binaries> <sonar.exclusions>***some paths here doesnt conflict***</sonar.exclusions>
-
jacoco plugin config:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>verify</phase> <goals> <goal>report</goal> </goals> <configuration> <outputDirectory>${project.basedir}/target/site/jacoco</outputDirectory> <excludes> <exclude>***some_eclusitions***</exclude> </excludes> </configuration> </execution> </executions> </plugin>
-
related dependencies:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency>
2) dev-ci.yml file
jobs:
run:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_MAVEN_PLUGIN_VERSION: 5.1.0.4751
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21.0.1'
distribution: 'temurin'
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build test and sonar scan
run: |
mvn -s .github/setting.xml clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:${{env.SONAR_MAVEN_PLUGIN_VERSION}}:sonar -Dsonar.verbose=true
Finally attaching the verbose logs of sonar:
[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=62ms
sonar_logs.txt (17.7 KB)
any help is appreciated, Thank You in advance!