# Android multi module project with Gradle connection Sonarqube

**URL:** <https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632>\
**Category:** SonarQube Server / Community Build\
**Tags:** multi-module, gradle, android, kotlin, sonarqube\
**Created:** [September 28, 2023, 1:43pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632 "2023-09-28T13:43:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [September 28, 2023, 1:43pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/1 "2023-09-28T13:43:27Z")

</div>

I have a multi-module project

 ![Снимок экрана 2023-09-26 в 18.25.26](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/7/9/79c315833d6afe06f223fbc6fbf3408f88673eca.jpeg)

I add a SonarQube property to the root gradle

```auto
sonarqube {
    properties {
        property("sonar.sourceEncoding", "UTF-8")
        property("sonar.projectName", "projectName")
        property("sonar.projectKey", "projectKey")
        property("sonar.host.url", "url")
        property("sonar.login", "login")
        property("sonar.language", "kotlin")
        property("sonar.sources", "src/main/")
        property("sonar.tests.exclusions", "src/main/**",)
        property("sonar.tests", "src/main/")
    }
}

```

Use sonarqube ver 4.0.0.2929

But the report contains the results of scanning only xml files

 ![Снимок экрана 2023-09-28 в 16.32.22](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/0/b/0b2e4a7086b9ed29ed4ff358ebb1923b7799a814.png)

![Снимок экрана 2023-09-28 в 16.39.02](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/7/d7367171380807b87c161a8e4df47866146ce45a.png)  
When I configured in Gradle file modules with these properties at the very beginning, all files were scanned. But since I needed to include all the modules in the report, I moved them to the gradle root

How can I get sonar to scan a kotlin file?

---

<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:** [September 29, 2023, 4:40pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/2 "2023-09-29T16:40:13Z")

</div>

Hi,

Version 4.0.0 has a little age on it now. Can you upgrade to the [current version](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/), 4.4.0.3356 and try again?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 2, 2023, 7:35am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/3 "2023-10-02T07:35:59Z")

</div>

Hi  
Honestly, I don’t think this has anything to do with the version, because with ver 3, when defining properties in the gradle module, sonarqube read Kotlin

---

<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:** [October 2, 2023, 12:39pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/4 "2023-10-02T12:39:25Z")

</div>

Hi,

> [@Kristina](#):
>
> Honestly, I don’t think this has anything to do with the version, because

Okay, but I’m almost immediately out of my depth with Gradle & I can’t escalate for help if you’re not on the latest version.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 3, 2023, 8:06am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/5 "2023-10-03T08:06:07Z")

</div>

After updating I get an error in BuildExceptionReporter package org.gradle.internal.buildevents

- What went wrong:

Execution failed for task ‘:sonarqube’.

> class java.lang.String cannot be cast to class java.util.Collection (java.lang.String and java.util.Collection are in module java.base of loader ‘bootstrap’)  
> Use in project Gradle ver 8.0.2 AGP 8.0.2

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 3, 2023, 10:00am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/6 "2023-10-03T10:00:48Z")

</div>

oh, I fix it, remove .gradel dir) but it also does not scan kotlin files (  
in version 4.4.0.3356)

---

<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:** [October 3, 2023, 12:24pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/7 "2023-10-03T12:24:55Z")

</div>

Hi,

So you’ve upgraded, but are still seeing an error? Can you provide full, debug analysis logs?

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](https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317) will help you find them.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 4, 2023, 6:36am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/8 "2023-10-04T06:36:23Z")

</div>

Hi,  
Yes, that’s right, let me remind you that when I declared sonarqube and its properties in the garadle module, it scanned Kotlin, and when I brought it to root, it stopped transferring  
[log.txt](https://community.sonarsource.com/uploads/short-url/ZWvuSPtdwrFp6NTaxGaeaPf7C0.txt) (7.1 MB)

---

<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:** [October 4, 2023, 1:25pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/9 "2023-10-04T13:25:27Z")

</div>

Hi,

Is this a `--debug` log? Also, could you share your configuration?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 13, 2023, 12:23pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/10 "2023-10-13T12:23:52Z")

</div>

Hi,  
sorry for the delay, what configuration are you referring to?

---

<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:** [October 13, 2023, 2:21pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/11 "2023-10-13T14:21:45Z")

</div>

Hi,

> [@Kristina](#):
>
> what configuration are you referring to?

It’s been a week and a half. I don’t remember 😂

Based on the log you posted, it seems your analysis command was this?

> `+ gradle sonarqube\`

I.e. you didn’t add the `--debug` specified in the guide I linked earlier?

That means that in 78k lines of logging, there’s no analysis logging, only the mention of the task and about 2k lines about missing JaCoCo reports. There’s nothing to go on here.

Looking back at your OP

> [@Kristina](#):
>
> `property("sonar.language", "kotlin")`

This does nothing. You can drop it.

> [@Kristina](#):
>
> ```auto
> property("sonar.tests.exclusions", "src/main/**",)
> property("sonar.tests", "src/main/")
> 
> ```

I don’t understand the point of this pair. Your test exclusion covers everything you’ve configured for `sonar.tests`.

And per [the docs](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/), `sonar.sources`, `sonar.tests`, `sonar.projectName` and `sonar.projectKey` default to what’s read from your build environment.

I suggest paring this back a bit and trying again **with the `--debug` flag** :

> [@Kristina](#):
>
> ```auto
> sonarqube {
> properties {
> property("sonar.sourceEncoding", "UTF-8")
> property("sonar.host.url", "url")
> property("sonar.login", "login")
> }
> }
> 
> ```

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 17, 2023, 6:26am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/12 "2023-10-17T06:26:37Z")

</div>

Hi,  
what about sonar.projectName & sonar.projectKey, deleting them too?

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 17, 2023, 9:25am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/14 "2023-10-17T09:25:25Z")

</div>

[sonar debug.txt](https://community.sonarsource.com/uploads/short-url/tR3Re39ytdFSvYq6mmHge4C306u.txt) (1.5 MB)  
there are difficulties with gradle sonarqube --debug, there are a lot of logs, when running on Jenkins the browser crashes when you view them, and locally if you run it shows only the last part, the logs don’t look informative

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 17, 2023, 9:26am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/15 "2023-10-17T09:26:06Z")

</div>

It seems the problem is still in the gradle declarations, perhaps there is a specialist who can help with this?

---

<div class="post-metadata">

**Author:** ![G00fY2](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/g00fy2/32/19724_2.png) [@G00fY2](https://community.sonarsource.com/u/G00fY2)\
**Post date:** [October 17, 2023, 1:57pm UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/16 "2023-10-17T13:57:11Z")

</div>

> [@Kristina](#):
>
> When I configured in Gradle file modules with these properties at the very beginning, all files were scanned. But since I needed to include all the modules in the report, I moved them to the gradle root
> 
> How can I get sonar to scan a kotlin file?

We use SonarQube (with it’s Gradle plugin) in a multi module (150+) Android project (with one Android app module and a mix of many Android-library and Kotlin-only modules). We use custom [convention plugins](https://github.com/android/nowinandroid/tree/main/build-logic#convention-plugins) to set up each module properly. In these convention plugins we apply SonarQube plugin per module and set the required properties.  
This is working fine. So you should consider moving to a similar approach.

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 20, 2023, 9:34am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/17 "2023-10-20T09:34:56Z")

</div>

in this repository are you using sonar? I just can’t find his ad.

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 20, 2023, 9:58am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/18 "2023-10-20T09:58:12Z")

</div>

and another question, if I make a convention plugin, do I need to specify some sonar properties in gradle root?

---

<div class="post-metadata">

**Author:** ![G00fY2](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/g00fy2/32/19724_2.png) [@G00fY2](https://community.sonarsource.com/u/G00fY2)\
**Post date:** [October 23, 2023, 9:42am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/21 "2023-10-23T09:42:28Z")

</div>

> [@Kristina](#):
>
> do I need to specify some sonar properties in gradle root?

Yeah sure. You still need to apply the plugin to the root project and set the `projectKey`, token etc. there. In your submodules you then also apply the plugin but only set your `exclusions`, `reportPaths`, `sonar.tests` path and so on.

---

<div class="post-metadata">

**Author:** ![Kristina](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/kristina/32/49110_2.png) [@Kristina](https://community.sonarsource.com/u/Kristina)\
**Post date:** [October 26, 2023, 10:58am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/22 "2023-10-26T10:58:48Z")

</div>

Thank you very much, you helped me a lot)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [November 2, 2023, 10:58am UTC](https://community.sonarsource.com/t/android-multi-module-project-with-gradle-connection-sonarqube/101632/23 "2023-11-02T10:58:57Z")

</div>

Closed on November 2, 2023, 10:58am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
