# Sonarcloud Pull request analysis code coverage showing empty -coverage

**URL:** <https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729>\
**Category:** SonarQube Cloud\
**Tags:** sonarqube-cloud, coverage\
**Created:** [December 8, 2023, 1:53pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729 "2023-12-08T13:53:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 8, 2023, 1:53pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/1 "2023-12-08T13:53:33Z")

</div>

Bitbucket Cloud

CI: Jenkins

Scanner command used within the pipeline script in Jenkins: script {

```
        withSonarQubeEnv('sonarcloud') {
            sh """
                 mvn -s settings.xml clean verify sonar:sonar \
                -Dsonar.organization=projectname \
                -Dsonar.projectKey=key \
                -Pcoverage
                
                ${SCANNER_HOME}/bin/sonar-scanner \
                -Dsonar.projectKey=projectname \
                -Dsonar.organization=name \
                -Dsonar.host.url=https://sonarcloud.io \
                -Dsonar.token=${env.SONAR_TOKEN} \
                -Dsonar.java.coveragePlugin=jacoco \
                -Dsonar.java.binaries=target/classes \
                -Dsonar.jacoco.reportPaths=target/site/jacoco/jacoco.xml \
                -Dsonar.pullrequest.key=${env.CHANGE_ID} \
                -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
                -Dsonar.pullrequest.base=${env.CHANGE_TARGET}
                """
                }

```

The code is private

Problem report:

The analysis is coming to zero, I need help identifying the problem and using the same steps i can abe to see code coverage percentage in branch analysis and for PR analsysis its -coverage and below to that i can able to see estimated percentage to merge like below screen shot

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/8/5838dd7f149fed32e7b2a6edce72d92832024569.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 11, 2023, 5:51pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/2 "2023-12-11T17:51:03Z")

</div>

Hi,

Welcome to the community!

You seem to run a Maven analysis and immediately after a second analysis using the SonarScanner CLI? I don’t understand why you would do that. What’s your build technology?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 12, 2023, 7:57am UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/3 "2023-12-12T07:57:44Z")

</div>

why im doing 2 analysis means with above only im getting code coverage for branch analsysis and its not happening for PR analysis and build techonology using Maven as the build technology for my Java backend project

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 12, 2023, 2:52pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/4 "2023-12-12T14:52:13Z")

</div>

Hi,

Can you share your full job log, starting from the checkout?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 12, 2023, 5:29pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/5 "2023-12-12T17:29:24Z")

</div>

deleted

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 12, 2023, 6:31pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/6 "2023-12-12T18:31:50Z")

</div>

Hi,

Thanks for the logs.

I have a few general observations:

First,

> `[e[1;34mINFOe[m] 2 languages detected in 19 preprocessed files`  
> …  
> `INFO: 4 languages detected in 28 preprocessed files`

Your two analyses have different initial scopes. I say ‘initial’ because the scope for the PR is subsequently narrowed to only those files changed in the PR.

Your Maven analysis uses sonar-maven-plugin:3.9.1.2184, which is one version behind. The latest version includes

> [MSONAR-190](https://sonarsource.atlassian.net/browse/MSONAR-190) - Default sources to “src/main” instead of “src/main/java”

which may be helpful in this regard. However, you seem to be letting `sonar.sources` default to `.` in the SonarScanner CLI analysis, so it may still end up with some additional scope.

Second, this parameter, which you pass to the 2nd analysis, does nothing:

> `-Dsonar.java.coveragePlugin=jacoco`

Similarly,

> `-Dsonar.jacoco.reportPaths=target/site/jacoco/jacoco.xml`

is also a `noop`, as noted in your log:

> `WARN: Property 'sonar.jacoco.reportPaths' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.`

Now the good news is that the location of your coverage report is automatically checked:

> ```auto
> INFO: Sensor JaCoCo XML Report Importer [jacoco]
> 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=78ms
> 
> ```

So it seems that your coverage report _is_ read.

Which brings me back to your original post, where you complain that coverage is “coming to zero”. But actually, the screenshot you provided shows it as `-`. The distinction is significant. A 0% coverage means there was coverage to measure and it came to 0%. A `-` coverage means there was no measurement. The question is “Why?”. You passed in a coverage report and the log says it was read.

So let’s come back to what I said earlier:

> the scope for the PR is subsequently narrowed to only those files changed in the PR.

If no _code_ files were changed in the PR, then it’s quite legitimate to have 0 issues and `-` for coverage and duplications.

So, what files were changed?  
&nbsp;

And with all that said, I’m still not understanding why you’re doing two analyses. Is the end goal to have branch analysis or PR analysis?

If it’s PR analysis that you’re truly after, then run the one, Maven analysis (i.e. use the scanner that aligns with your build technology) and pass in your PR parameters on the command line. (The fact that you need to pass them manually is another topic, related to how you’re doing your checkout, I believe.)

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 13, 2023, 3:14am UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/7 "2023-12-13T03:14:55Z")

</div>

Thanks ann, But, answer to your question  
My require ment need to run PR analysis in sonarcloud with code coverage  
build tech: maven  
Tried below steps with same build technlogy already dnt get code coverage after that added sonar stepd also, for that got code coverage in branch analysis and but my requirment need to run sonarcloud analysis only for all PR --\>PR analysis need to run , any suggestion  
withSonarQubeEnv(‘###’) {  
sh “mvn -s settings.xml verify sonar:sonar -Dsonar.projectKey=projectkey -Dsonar.pullrequest.key=${env.CHANGE\_ID} -Dsonar.pullrequest.branch=${env.CHANGE\_BRANCH} -Dsonar.pullrequest.base=${env.CHANGE\_TARGET}”

```
              }

```

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/e/5e09f16f572b47e6926af650af39002a78a54451.png)

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 13, 2023, 8:16am UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/8 "2023-12-13T08:16:15Z")

</div>

My issue still not resolved

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 13, 2023, 2:44pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/9 "2023-12-13T14:44:25Z")

</div>

Hi,

I still need to know:

> [@ganncamp](#):
>
> So, what files were changed?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 13, 2023, 5:30pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/10 "2023-12-13T17:30:18Z")

</div>

13 files we changed and raised PR for that and attached screenshot for your reference  
Below screen shot from bitbucket cloud

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/4/8/489f18251e8e33be14bb78ba113a7ff47fee14e8.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 13, 2023, 6:07pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/11 "2023-12-13T18:07:42Z")

</div>

Hi,

This looks like a mismatch to me. Your earlier screenshot showed

- 0 Bugs
- 0 Code Smells
- 0 Vulnerabilities
- 0 Security Hotspots

This one shows

- 6 issues

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 14, 2023, 1:01pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/12 "2023-12-14T13:01:23Z")

</div>

yes its not reflect too, simple can you provided me steps to run PR analaysis with code coverage enabled for maven builds and jacoco has been added in pom.xml also

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [December 14, 2023, 2:41pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/13 "2023-12-14T14:41:07Z")

</div>

Hi,

Per [the docs](https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/java-test-coverage/#add-coverage-in-a-single-module-maven-project)

> `mvn -Dsonar.coverage.jacoco.xmlReportPaths=../app-it/target/site/jacoco-aggregate/jacoco.xml sonar:sonar -Pcoverage`

And make sure to manually add your PR parameters if needed.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [December 18, 2023, 8:43am UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/14 "2023-12-18T08:43:16Z")

</div>

As per reply, added the path also but still is not showing the coverage and if no files changed means its hould show 100% right, why its not showing that also let me attach latest changes made after your reply and attaching the logs for your reference

Note: I’m having issue only in PR analysis sonarcloud using the same syntax below its showing coverage for branch analysis  
[newsonarlogs.txt](https://community.sonarsource.com/uploads/short-url/ld4mNSI2s5pjo0qZ1fzHQalQRlc.txt) (46.4 KB)

Jenkinsfile:  
script {

```
        withSonarQubeEnv('sonarcloud') {
            sh """
                mvn -s settings.xml clean verify sonar:sonar \
                -Dsonar.organization=projectname \
                -Dsonar.projectKey=projectname_dev \
                -Dsonar.host.url=https://sonarcloud.io \
                -Dsonar.token=${SONAR_TOKEN} \
                -Dsonar.java.coveragePlugin=jacoco \
                -Dsonar.java.binaries=target/classes \
                -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml sonar:sonar -Pcoverage \
                -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
                -Dsonar.pullrequest.key=${env.CHANGE_ID} \
                -Dsonar.pullrequest.base=${env.CHANGE_TARGET}
                 """
                 }

```

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 3, 2024, 4:09pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/15 "2024-01-03T16:09:48Z")

</div>

Hi,

> [@Keerthu](#):
>
> if no files changed means its hould show 100% right,

No. I think it would probably show ‘-’.

> [@Keerthu](#):
>
> I’m having issue only in PR analysis sonarcloud using the same syntax below its showing coverage for branch analysis

Okay, then everything is configured correctly, and (apparently) what’s changed in your PR is not cover-able, I.E. not something that _can be_ covered by unit tests.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Keerthu](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@Keerthu](https://community.sonarsource.com/u/Keerthu)\
**Post date:** [January 3, 2024, 4:29pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/16 "2024-01-03T16:29:09Z")

</div>

If its not covered by unit tests means , included in exclusions , we are not able to any coverage its blank

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 3, 2024, 6:14pm UTC](https://community.sonarsource.com/t/sonarcloud-pull-request-analysis-code-coverage-showing-empty-coverage/105729/17 "2024-01-03T18:14:17Z")

</div>

Hi,

Sorry, I don’t understand.

&nbsp;  
Ann
