Kotlin DSL SQ Multi Module using gradle plugin 3.3

Hi,
I have a multi-module/project environment in which I am trying to post coverage for all modules. My issue is I see report for only one module, seems like it is getting over-written. I tried to replicate the instructions here to establish the directory structure but it’s not working. I am also using a Modules.json for project structure but sonarqube is not reflecting the directory structure. Has anyone else experienced similar issues?

Hello,

I’m not sure I can help for your topic about loading the coverage but I believe it’s important to have in mind that the concept of modules no longer exists in SonarQube since https://jira.sonarsource.com/browse/MMF-365 was implemented.
I would suggest to drop any config your tried to do in the past and just scan your code with Gradle. Then the question will be: do you see already all the files / directories of your project in SonarQube?

Once this is confirmed and OK, you should configure this property:

sonar.coverage.jacoco.xmlReportPaths

… which accepts wildcards configuration.

Path to JaCoCo XML coverage reports. Path wildcards are supported (see above).

Would you mind also share some context: which version of SonarQube is used?

Alex

Hello,

Thanks for responding. I am using an older version of sonarqube, 7.9.1. I have a nested multi-module android/kotlin project where coverage reports for individual projects/subproject are generated gracefully using jacoco plugin/tasks. I am trying to integrate sonarqube for coverage report for all subprojects using the plugin. Following code iterates through all the projects but only the last project scanned appears in the sonar web UI.


fun Project.configureSonarqube() {
    apply {
        plugin("org.sonarqube")
        plugin("jacoco")
    }
    val defaultExcludes = listOf(
            "*.json",
            "*.xml",
            "*.html",
            "**/assets/**",
            "**/*Test*/**",
            "**/res/**",
    )
    val xmlReport = when {
        directoryExists("buildDir/reports/jacoco/testDeveloperReleaseUnitTestCoverage") -> {
            "$buildDir/reports/jacoco/testDeveloperReleaseUnitTestCoverage/testDeveloperReleaseUnitTestCoverage.xml"
        }
        else -> {
            "$buildDir/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml"
        }
    }

    val binaries = when {
        directoryExists("$buildDir/intermediates/javac/developerRelease") -> {
            "$buildDir/intermediates/javac/developerRelease/classes"
        }
        else -> {
            "$buildDir/intermediates/javac/release/classes"
        }
    }
    tasks.named("sonarqube").configure {
        allprojects {
            sonarqube {
                properties {
                    property("sonar.java.coveragePlugin", "jacoco")
                    property("sonar.exclusions", "$defaultExcludes")
                    property("sonar.coverage.jacoco.xmlReportPaths", "$xmlReport")
                    property("sonar.java.binaries", "$binaries")
                    property("sonar.cpd.exclusions", "**")
                }
            }
        }
    }
}