# Gradle Subprojects not reported to Sonarcloud for Github Pull Requests

**URL:** <https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164>\
**Category:** SonarQube Cloud\
**Tags:** modules, gradle, sonarqube-cloud\
**Created:** [June 12, 2018, 11:24am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164 "2018-06-12T11:24:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [June 12, 2018, 11:24am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/1 "2018-06-12T11:24:40Z")

</div>

Hi,

we currently run scans and report to sonarcloud with the “sonar.analysis.mode=preview” option for github pull requests. We tried to move to the new pull request reporting option as outlined here [https://blog.sonarsource.com/sonarcloud-loves-your-build-pipeline](https://blog.sonarsource.com/sonarcloud-loves-your-build-pipeline) with the new sonarcloud github app.  
We noticed though, that the submodules in our gradle project are not reported any more. The log shows that they are analyzed, but the “code” Tab does not show them and errors we put in there intentionally do not show up.  
Any idea why that happens? Do we have to set any extra options to make this work?

Regards,  
Sebastian

---

<div class="post-metadata">

**Author:** ![simon.brandhof](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/simon.brandhof/32/33_2.png) [@simon.brandhof](https://community.sonarsource.com/u/simon.brandhof)\
**Post date:** [June 13, 2018, 7:19am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/2 "2018-06-13T07:19:09Z")

</div>

Hi Sebastian,

This is the expected behavior. Analysis report is only about the changed code on pull requests, even if technically all the source code is analysed.  
Here is an example : [https://sonarcloud.io/code?id=org.sonarsource.dotnet%3Asonar-csharp&pullRequest=1452](https://sonarcloud.io/code?id=org.sonarsource.dotnet%3Asonar-csharp&pullRequest=1452). Only some tests have been touched.

Regards

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [June 13, 2018, 7:34am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/3 "2018-06-13T07:34:57Z")

</div>

Hi Simon,

ok, i understand but the changed code is within the subproject (the main project is basically empty).  
We tested the same PR with the “new” handling and the old one. The old setup did create a github comment with the expected issues. The new setup does not. The sonarcloud check shows up though and we can view the PR in sonarcloud, so it is processed.

Regards,  
Sebastian

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [June 19, 2018, 1:04pm UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/4 "2018-06-19T13:04:29Z")

</div>

Hi,

is there a hint on what we could try here? We would really like to use the new github features 🙂

Regards,  
Sebastian

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [August 31, 2018, 7:33am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/5 "2018-08-31T07:33:52Z")

</div>

Hi @SebMel

Sorry for the late reply. I would like to find the issue with you, since we are not expecting any difference here compared to the previous mechanism.

Let me sum up:

- you have a Gradle project, with some subprojects
- this project master branch is analyzed on SonarCloud
- you change a file in one subproject, so that an issue should be created, and you push this to a branch
- you open a pull request on GitHub and the pull request appears in SonarCloud, but it is empty (no files in the code viewer)

Am I correct?

Few questions:

- how is your analysis triggered? Are you using the travis addon for example? If not, what are the parameters you pass for the pullrequest decoration?
- is the PR analysis triggered on the Git branch you created, or on the merge commit created by GitHub?
- can you share with me the scanner logs, with verbose mode enabled (`--debug` with Gradle). Feel free to send them to me privately

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [September 4, 2018, 9:12am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/6 "2018-09-04T09:12:44Z")

</div>

Hi Julien,

thanks for getting back to me. Your summary is correct, we scan the pull request and the subproject code is not showing up in sonarcloud and the issues we created in that branch are not reported.

Regarding your questions:

- The analysis is triggered in our circleci job using the gradle plugin. The args are:  
./gradlew sonarqube -Dsonar.host.url=https://sonarcloud.io   
-Dsonar.organization=orgabc   
-Dsonar.login=\<\>   
-Dsonar.projectKey="${CIRCLE\_PROJECT\_REPONAME}:master"   
-Dsonar.pullrequest.key=${CIRCLE\_PULL\_REQUEST##\*/}   
-Dsonar.pullrequest.base=master   
-Dsonar.pullrequest.provider=GitHub   
-Dsonar.pullrequest.branch=${CIRCLE\_BRANCH}   
-Dsonar.pullrequest.github.repository=$CIRCLE\_PROJECT\_USERNAME/$CIRCLE\_PROJECT\_REPONAME"  
The sonarcloud github app has been added to our github org, and we see " **SonarCloud** — Code Quality check passed" in the pull request.  
The analysis is running on the PR.  
I have generated a debug log, but how can i send it to you privately?

Regards,  
Sebastian

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [September 18, 2018, 12:42pm UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/7 "2018-09-18T12:42:16Z")

</div>

Hi @Julien_HENRY would be great if you could get in touch!

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [September 18, 2018, 3:48pm UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/8 "2018-09-18T15:48:19Z")

</div>

@dmeneses you told me about a bug in circleci that would erase the master branch. Could it be the reason why we are unable to detect changed files here?

---

<div class="post-metadata">

**Author:** ![dmeneses](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dmeneses/32/2933_2.png) [@dmeneses](https://community.sonarsource.com/u/dmeneses)\
**Post date:** [September 19, 2018, 7:21am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/9 "2018-09-19T07:21:31Z")

</div>

It could be.  
Here is the ticket open in circle ci: [Git checkout of a branch destroys local reference to master - Feedback & Bug Reports - CircleCI Discuss](https://discuss.circleci.com/t/git-checkout-of-a-branch-destroys-local-reference-to-master/23781)  
And the other user reporting empty P/R: [Code is empty on Pull Request reviews](https://community.sonarsource.com/t/code-is-empty-on-pull-request-reviews/822)

@SebMel Having the logs of the scanner would indeed help. I’ve sent you a private message to which you can reply with the logs.

Please try the same workaround discussed in the other topic.

> Thanks.  
> So the only thing we can think of is that the clone of the git repository in `circleci` has some references that are no longer valid.  
> Could you please add, to the P/R, the following to the beginning of your build script.
> 
> ```auto
> git fetch --all
> git branch -D master
> git rev-parse origin/master
> 
> ```
> 
> This will update all remote references, delete local master branch (if exists) and print the current remote reference to master.

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [September 19, 2018, 7:35am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/10 "2018-09-19T07:35:19Z")

</div>

Thanks, i added the logs to the private message and i will try the workaround you mentioned tomorrow 😄

---

<div class="post-metadata">

**Author:** ![SebMel](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/sebmel/32/842_2.png) [@SebMel](https://community.sonarsource.com/u/SebMel)\
**Post date:** [September 20, 2018, 7:23am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/11 "2018-09-20T07:23:02Z")

</div>

The issue is fixed with this workaround! We can now see the correct reports in sonarcloud. Thanks!

---

<div class="post-metadata">

**Author:** ![alessandro-candon](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alessandro-candon/32/4182_2.png) [@alessandro-candon](https://community.sonarsource.com/u/alessandro-candon)\
**Post date:** [May 23, 2019, 11:37am UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/12 "2019-05-23T11:37:34Z")

</div>

Hello,  
I try with your workaround but no good news…

Do you still use the circleci checkout?

Thank you

---

<div class="post-metadata">

**Author:** ![dmeneses](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dmeneses/32/2933_2.png) [@dmeneses](https://community.sonarsource.com/u/dmeneses)\
**Post date:** [May 23, 2019, 6:13pm UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/13 "2019-05-23T18:13:56Z")

</div>

Hi Alessandro,

If the workaround is not working for you, you might be having a different problem.  
Do you have any debug logs to show?

---

<div class="post-metadata">

**Author:** ![pete-woods](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@pete-woods](https://community.sonarsource.com/u/pete-woods)\
**Post date:** [February 5, 2021, 2:10pm UTC](https://community.sonarsource.com/t/gradle-subprojects-not-reported-to-sonarcloud-for-github-pull-requests/164/14 "2021-02-05T14:10:36Z")

</div>

We believe we have fixed this issue upstream at CircleCI now: [Git checkout of a branch destroys local reference to master - #16 by pete-woods - Feedback & Bug Reports - CircleCI Discuss](https://discuss.circleci.com/t/git-checkout-of-a-branch-destroys-local-reference-to-master/23781/16)
