SonarQube misses a lot of source code in Gradle multiple projects/modules

We are not able to make SonarQube work properly with Gradle multiple projects. This is an Android application and we use custom preconfigured plugins for these multiple projects.
we have structure like this:

app - main module with application and lots of legacy  code, Java and Kotlin mix
feature - directory with modules and refactored clean architecture code, Kotlin only
|---attachment
|---dashboard
|---notification
...
network
|---core   - some networking code to connect with API
build.gradle.kts
settings.gradle.kts


You see we only have source code from the app module and one of the submodules. According to logs (I can’t publish them publicly, only privately) it’s going over all of them.

allprojects {
    apply(plugin = "org.sonarqube")
    //region SonarQube
    sonar {
        val androidCodeExclusion = listOf(
            "**/databinding/**/*.*",
            "**/android/databinding/*Binding.*",
            "**/BR.*",
            "**/R.*",
            "**/R$*.*",
            "**/BuildConfig.*",
            "**/Manifest*.*",
            "**/mockserver/**"
        )

        properties {
            //SonarQube use local.properties if any
            val properties = Properties()
            try {
                properties.load(FileInputStream(rootProject.file("local.properties")))
            } catch (e: IOException) {
                System.err.println("local.properties didn't load (${e.message}).")
            }
            val sonarHostUrl = "sonar.host.url"
            property(sonarHostUrl, properties.getProperty(sonarHostUrl) ?: System.getenv("SONAR_HOST_URL"))
            property("sonar.projectKey", "<xxxxxxxxxxxxx>")
            property("sonar.projectName", "<xxxxxxxxxxxxx>")
            property("sonar.projectBaseDir", rootProject.projectDir)
            property("androidVariant", "debug")
            property("sonar.java.binaries", "build/")
            val sonarLogin = "sonar.login"
            val localLogin = properties.getProperty(sonarLogin)
            property(sonarLogin, localLogin ?: System.getenv("SONAR_TOKEN"))
            property("sonar.sourceEncoding", "UTF-8")
            property("sonar.scm.exclusions.disabled", true)
            //property("sonar.inclusions", "**/main/java/**, **/main/kotlin/**")
            property("sonar.exclusions", androidCodeExclusion.joinToString(","))
            property("sonar.coveragePlugin", "jacoco")
            property("sonar.coverage.jacoco.xmlReportPaths", "**/reports/jacoco/jacocoTestReport.xml")
        }
    }
    //endregion
}

I tried to remove exclusions, turn on and on scm.exclusions. And it didn’t help, code in all but one subprojects is missing.

Also there are some weird errors from the log that might be related, but I don’t know what to do with them:

2023-09-21T21:30:07.3145486Z Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
2023-09-21T21:30:07.3146466Z ECJ Unable to resolve type android.content.ContentProvider
2023-09-21T21:30:07.3147239Z org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
2023-09-21T21:30:06.7669676Z 
2023-09-21T21:30:06.7669825Z > Task :sonar
2023-09-21T21:30:07.1151739Z Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
2023-09-21T21:30:07.1154393Z Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor -  on file 'app/src/main/java/com/xxxxx/common/ui/fragments/BaseFragment.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/

Of course it’s not showing code coverage as well, but we have only new modules at least somehow covered.

Must-share information:

  • SonarQube Enterprise Edition Version 9.9 (build 65466), gradle sonarqube plugin 4.3.0.3225
  • how is SonarQube deployed: not sure, but this is probably a client side issue with gradle plugin
1 Like

Hey there.

You will need to make sure that sonar.sources includes your other folder. You can see how the default settings are being derived in this documentation, as well as how to add additional source sets.

Unfortunately, I’m not sure what to fill there. We don’t use any special source sets. It’s definitely going through all the modules and we have src/main/kotlin and src/test/kotlin.

subprojects {
    apply(plugin = "org.sonarqube")
    sonar {
        properties {
            property("sonar.sources", "src/main")
            property("sonar.tests", "src/test")
        }
    }