New code coverage is 0 when it actually exists

Hi all,

I’m having an issue with SonarQube. I configured my pom.xml properties as follows:

    <properties>
        <sonar.projectKey>***</sonar.projectKey>
        <sonar.projectName>****</sonar.projectName>
        <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
        <sonar.sources>src/main/java</sonar.sources>
        <sonar.tests>src/test/java</sonar.tests>
        <sonar.exclusions>src/main/webapp/WEB-INF/classes/**/*</sonar.exclusions>
        <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
    </properties>

Here are the relevant parts of the logs:

[INFO] 15:52:18.012 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 15:52:18.042 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[INFO] 15:52:19.462 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1451ms
[INFO] 15:52:19.462 Sensor IaC Docker Sensor [iac]
[INFO] 15:52:19.462 Sensor IaC Docker Sensor is restricted to changed files only
[INFO] 15:52:19.550 0 source files to be analyzed
[INFO] 15:52:19.554 0/0 source files have been analyzed
[INFO] 15:52:19.554 Sensor IaC Docker Sensor [iac] (done) | time=92ms
[INFO] 15:52:19.555 Sensor Java Config Sensor [iac]
[INFO] 15:52:19.682 0 source files to be analyzed
[INFO] 15:52:19.682 0/0 source files have been analyzed
[INFO] 15:52:19.683 Sensor Java Config Sensor [iac] (done) | time=128ms
[INFO] 15:52:19.768 Sensor SurefireSensor [java]
[INFO] 15:52:19.769 parsing [/builds/***/****/target/surefire-reports]
[INFO] 15:52:19.976 Sensor SurefireSensor [java] (done) | time=207ms

Im getting the 0% test coverage on new code error, but actually new tests is exists

The problem is that SonarQube shows 0% test coverage on new code, even though the tests exist.

I’ve already tried following this topic( JaCoCo coverage is 0% ), but it didn’t help.

Could someone help me figure out why SonarQube is not detecting my test coverage?

Sonar version: Developer Edition v2025.2 (105476)
Jacoco maven plugin version: 0.8.10
Surefile maven plugin version: 2.19.1

Hi,

Can you add -Dsonar.verbose=true to your analysis command and provide that analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi, yep

From yesterday i’ve update my pom props
Now it looks like this

        <sonar.projectKey>***</sonar.projectKey>
        <sonar.projectName>***</sonar.projectName>
        <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
        <sonar.sources>src/main/java</sonar.sources>
        <sonar.tests>src/test/java</sonar.tests>
        <sonar.java.binaries>src/main/webapp/WEB-INF/classes</sonar.java.binaries>
        <sonar.java.test.binaries>target/test-classes</sonar.java.test.binaries>
        <sonar.junit.reportPaths>target/surefire-reports</sonar.junit.reportPaths>
     <sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
[INFO] 11:34:49.433 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[DEBUG] 11:34:49.433 Reading report '/builds/***/***/target/site/jacoco/jacoco.xml'
[INFO] 11:34:50.684 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1272ms
[INFO] 11:34:50.684 Sensor IaC Docker Sensor [iac]
[INFO] 11:34:50.684 Sensor IaC Docker Sensor is restricted to changed files only
[DEBUG] 11:34:50.691 'src/main/java/com/***/****/utils/test/ex4.groovy' generated metadata with charset 'UTF-8'
[DEBUG] 11:34:50.692 'src/main/java/com/***/****/utils/test/ex1.groovy' generated metadata with charset 'UTF-8'
[DEBUG] 11:34:50.693 'src/main/java/com/***/****/utils/test/ex2.groovy' generated metadata with charset 'UTF-8'
[DEBUG] 11:34:50.695 'src/main/java/com/***/****/utils/test/ex3.groovy' generated metadata with charset 'UTF-8'
[INFO] 11:34:50.781 0 source files to be analyzed
[INFO] 11:34:50.784 0/0 source files have been analyzed
[INFO] 11:34:50.785 Sensor IaC Docker Sensor [iac] (done) | time=101ms
[INFO] 11:34:50.785 Sensor Java Config Sensor [iac]
[INFO] 11:34:50.875 0 source files to be analyzed
[INFO] 11:34:50.875 0/0 source files have been analyzed
[INFO] 11:34:50.875 Sensor Java Config Sensor [iac] (done) | time=90ms
[INFO] 11:34:50.906 Sensor SurefireSensor [java]
[INFO] 11:34:50.907 parsing [/builds/***/****/target/surefire-reports]
[DEBUG] 11:34:51.197 Class not found in resource cache : ***(FQCN)
[DEBUG] 11:34:51.198 Class not found in resource cache : ***(FQCN)
[DEBUG] 11:34:51.198 Class not found in resource cache : ***(FQCN)
[DEBUG] 11:34:51.198 Class not found in resource cache : ***(FQCN)
[DEBUG] 11:34:51.198 Class not found in resource cache : ***(FQCN)
[DEBUG] 11:34:51.198 Resource not found: ***(FQCN)

I found that surefile .xml reports dont finds the compiled classes

Here my sonar command

mvn -U sonar:sonar \
      -Dmaven.wagon.http.ssl.insecure=true \
      -DskipTests=true \
      -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository \
      -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml \
      -Dsonar.java.binaries=src/main/webapp/WEB-INF/classes \
      -Dsonar.java.test.binaries=target/test-classes \
      -Dsonar.junit.reportPaths=target/surefire-reports \

p.s I’m sharing the compiled classes between jobs, and they are currently available under these paths

Hi,

Can you share the full analysis log, starting from the analysis command itself?

 
Thx,
Ann

sonar 3.log (27.9 MB)

That’s the most I can send.

Hi,

Oof. I got what I asked for, didn’t I? :sweat_smile: (Side note, I’m going to raise the over-the-top verbosity of these verbose logs internally.)

It looks like we’re dealing with analysis of a a PR in which 2 files changed. You said at the beginning, but I’d like to confirm. There are tests for the changed lines in PR? And are those tests new, i.e. added in the PR? Or are they existing tests? (Not, I think, that that should matter.)

I suppose that’s the changed file and its changed (so the tests are new too) test?

We’re not seeing anything about this explicitly in the logs, but a common problem for this symptom is that the paths in the coverage report don’t match the paths the analysis is seeing. Can you take a look at your JaCoCo report and see if the paths look right, relative to where analysis is kicked off from?

 
Thx,
Ann