SonarQube version 4.2.1.3168
Java 11
I am setting up SonarQube in GitLab CI for my Android project. However, I am facing issues with the setup. When I create a merge request, I do not receive the analysis from Sonar as expected. Below is the Sonar script I am using. Are there any alternative solutions to resolve this issue?
Attached is the Sonar script in gradle:
apply from: 'gradlescripts/coverage_criteria.gradle'
project(":sample") {
sonar {
skipProject = true
}
}
sonar {
androidVariant 'debug'
properties {
property "sonar.projectKey", "XXXXXX"
property "sonar.projectName", "XXXXXX"
property "sonar.organization", "XXXX"
property "sonar.tests", fileTree(dir: "$projectDir", includes: ['**/src/test/java', '**/src/test/kotlin']).files.join(", ")
property "sonar.sources", fileTree(dir: "$projectDir", includes: ['**/src/*/java', '**/src/*/kotlin']).files.join(", ")
property "sonar.test.inclusions", "**/*Test*/**"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.tags", "android"
property "sonar.scm.exclusions.disabled", "true"
property "sonar.qualitygate.wait", "true"
property "sonar.gitlab.unique_issue_per_inline", "true"
property "sonar.exclusions", generateSonarExclusion()
property "sonar.coverage.jacoco.xmlReportPaths", fileTree(dir: "$projectDir", includes: ['**/reports/jacoco/**/test*.xml']).files.join(", ")
property "sonar.androidLint.reportPaths", fileTree(dir: "$projectDir", includes: ['**/build/reports/lint-results-debug.xml']).files.join(", ")
property "sonar.junit.reportPaths",fileTree(dir: "$projectDir", includes: ['/XXXXX/build/test-results/testDebugUnitTest', '/XXXXX/build/test-results/testDebugUnitTest', '/XXXXX/build/test-results/test', '/XXXXX/build/test-results/testDebugUnitTest', ]).files.join(", ")
property "sonar.coverage.jacoco.xmlReportPaths", "${rootProject.buildDir}/reports/jacocoTestReport/jacocoTestReport.xml"
}
}
project.tasks.named("sonar").configure {
dependsOn 'jacocoTestReport'
dependsOn ':XXXX:lintDebug'
dependsOn ':XXXX:lintDebug'
dependsOn ':XXXX:lintDebug'
}
Then implement in Gitlab CI
sonar:
stage: Report
coverage: '/Total.*?([0-9]{1,3})%/'
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- ./gradlew sonar -Dsonar.host.url=$XXXX -Dsonar.token=$XXXX -Dsonar.pullrequest.key=$CI_MERGE_REQUEST_IID -Dsonar.pullrequest.branch=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$PROJECT_ID
- cat build/reports/jacocoTestReport/html/index.html | grep -o '<tfoot>.*</tfoot>'
<<: *retry_error
<<: *tags
<<: *gradle_cache
only:
refs:
- merge_requests
allow_failure: false
Notes:
I give XXXX to maintain privacy