Android multi module project with Gradle connection Sonarqube

I have a multi-module project

I add a SonarQube property to the root gradle

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.39.02
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?

Hi,

Version 4.0.0 has a little age on it now. Can you upgrade to the current version, 4.4.0.3356 and try again?

 
Thx,
Ann

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

Hi,

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.

 
Ann

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

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

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 will help you find them.

 
Ann

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 (7.1 MB)

Hi,

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

 
Thx,
Ann

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

Hi,

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

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

This does nothing. You can drop it.

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

And per the docs, 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:

 
Ann

1 Like

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

sonar debug.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

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

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 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.

1 Like

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

and another question, if I make a convention plugin, 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.

Thank you very much, you helped me a lot)

1 Like

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