Cover all gradle flavors in one Sonarquebe analysis
Asked Answered
W

0

7

Is it possible to run one Sonar analysis for all flavors? I have a multi flavored Android project where I have different implementations of some files in different flavor folders. Those files have their corresponding tests in flavor test folders. So in example my src structure is:

/main/java/../ConfigurationService.kt
/flavor1/java/../ConfigurationService.kt
/flavor2/java/../ConfigurationService.kt
/test/java/../ConfigurationServiceTests.kt
/testFlavor1/java/../ConfigurationServiceTests.kt
/testFlavor2/java/../ConfigurationServiceTests.kt

Now I can use sonarqube.androidVariant but that would let me configure only one variant at a time so if I want to check the analysis for the 2nd flavor I need to run the task again with different setting, and that does not work in Gitlab CI to show multiple analysis. I was able to configure separate jacoco tasks to generate coverage reports for all flavors prior to running sonar. I then tried adding source directories to sonarplugin like this:

sonarqube {
    properties {
            //standard plugin configuration
            android.libraryVariants.each { variant ->
                if (variant.buildType.name != "debug") return //we run sonar only on debug
                def variantName = variant.name
                def flavorName = variant.flavorName
                properties["sonar.sources"] += "./src/${flavorName}/"
                properties["sonar.tests"] += "./src/test${flavorName.capitalize()}"
                // and so on for binaries, jacoco report paths etc.
            }
    }
}

Unfortunately this ends up with an error:

ConfigurationService.kt can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Is there a way to cover all flavors among with test coverage in one sonar analysis? As I wrote before I can't have separate analysis for each flavor as Gitlab CI won't work with displaying multiple sonar results in merge requests.

Whitmore answered 28/5, 2020 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.