I’m facing issues when running a SonarQube scan for a specific Android variant (envSandboxDebug
) in a multi-module Android project. The entire AndroidVariants in the project is built before the scan, significantly increasing build time.
app
├── build.gradle
feature
├── feature-1
│ └── build.gradle
├── feature-2
│ └── build.gradle
data
├── data-module-1
│ └── build.gradle
├── data-module-2
│ └── build.gradle
build.gradle (root)
My App structure roughly look like this
I’m using Gradle for build management and have configured the SonarQube Gradle plugin to target the desired variant:
The sonar config block is put inside root build.gradle file hoping to scan all the modules inside my project
root build.gralde
plugins {
alias libs.plugins.sonarqube// version: "5.0.0.4638"
}
sonar {
properties {
androidVariant 'envSandboxDebug'
property "sonar.projectKey", "project_key"
property "sonar.projectName", "project_name"
property "sonar.host.url", "https://project_url.com"
}
}
When I try to run the sonar scan via GitHub Actions, each AndroidVariant is built and takes hours to complete.
......
........
# Install and configure Java 17 on the runner machine
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
# Cache SonarQube packages to speed up the build process
- name: Cache SonarQube packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
# Cache Gradle packages to speed up the build process
- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
# Download and unzip SonarQube scanner
- name: Sonar-scanning
run: sudo wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-macosx.zip && sudo unzip sonar-scanner-cli-4.7.0.2747-macosx.zip -d /opt/
# Run SonarQube analysis
- run: |-
./gradlew buildEnvSandboxDebug sonar -Dsonar.host.url=https://host-url.com \
-Dsonar.projectKey=project_key \
-Dsonar.projectName=project_name \
How do we solve this issue?