Sonarqube run for specific product flavor and build type (gradle plugin)
Asked Answered
S

3

7

Currently we are having problems running sonarqube for just a specific build variant. for example clienttestDebug

Our structure is like this. We have 3 different build types

  • Release
  • Debug
  • Profile

And has many (over 30) product flavors. For instance

 productFlavors {
        dev {

        }

        demo {

        }

        clienttest {

        }
        ...
     }

So we don't want to run the sonar to run for all variants. Normally there is a way documented as below

sonarqube {
    androidVariant 'clienttestDebug'
}

However the piece above doesn't work as expected and tries to run for all the variants. Is there something thats missing. We're using sonarqube plugin version 2.7

Suave answered 8/10, 2019 at 8:26 Comment(0)
I
6

I have found out that this issue is due to addition of plugin from root build.grade.

To learn more about the gradle plugins you can read: https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application

Also, to learn about adding sonarqube to multi-module projects: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/

You have to make the addition of the plugin in your root build.gradle as follows;

plugins {
  id "org.sonarqube" version "2.8"
}
subprojects {
    apply plugin: 'org.sonarqube'
    sonarqube {
        androidVariant "clienttestDebug"
    }
}

Hope this helps.

Invalidism answered 22/10, 2019 at 10:20 Comment(1)
Latest sonarqube gradle api is now sonar { androidVariant "clienttestDebug" }Delimitate
D
1

With the current version of sonarqube gradle plugin you must not use sonarqube {}, but sonar {} to configure the android variant.

See example below:

plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id "org.sonarqube" version "3.5.0.2730"
}

project(":app") {
    sonar {
        androidVariant 'betaDeveloperDebug'}
}
Delimitate answered 12/4, 2023 at 11:4 Comment(0)
V
0

Add this to the project level build gradle. You can run specified build variant like this.

project(":your_module") {
sonarqube {
    androidVariant 'your_variant'}
}
Velarium answered 1/2, 2023 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.