How to test multiple Android flavors with Gradle Sonar runner?

Hi all.

First of all, apologies if this is not the right forum for this question. Not quite sure where it belongs as it relates to Gradle, Android and Sonar.

I have an Android project with multiple build types and multiple flavors and trying to set up the Sonar runner to do analysis on this. Sonar runs fine currently with a single variant (one build type, one flavor). However, I’d like to get stats for all the flavors in the project. If I try to add sources/classes for more than one flavor, Sonar will complain that there are duplicate sources (as all the shared code from main would be present for each flavor).

Is there any way to set up the Gradle Sonar runner to handle and report on multiple Android flavors?

My current set up looks something like (which currently actually doesn’t include build type specific code),

sonarRunner {
        sonarProperties {
            property "sonar.sources", "src/main/java"
            property "sonar.binaries", "build/intermediates/classes/<flavor>/debug"
            property "sonar.libraries", "build/libs/*.jar"
            property "sonar.tests", "src/test/java"
            property "sonar.jacoco.reportPath", "build/jacoco/test<flavor>Debug.exec"
        }
    }

Perhaps you can use the ‘sonar.branch’ attribute (see Sonar docs for details).

Thanks for your reply Peter.

I did consider Sonar branches, but it’s not quite what I want as it would generate different Sonar projects. I’d like to have it all in just one Sonar project that covers all the code in the Android project.

Is there any other way - perhaps some way of filtering the sources/binaries to ensure that common code is only included once? Based on how Sonar properties are defined (paths rather than source sets), I couldn’t find any easy way of dynamically filtering what is fed to Sonar.

Thanks, Andreas

Gradle is fully scriptable, so chances are there is another way, once you fully understand the problem (I don’t).

Andreas, did you find a solution to your problem? I have the same issue.