- ALM used : GitHub
- CI system used : Circle CI
- Languages of the repository : Java, Kotlin
- Error observed : No errors.
- Steps to reproduce : Generate JaCoCo coverage report on system locally, then upload this report to SonarCloud.
- Potential workaround : None identified
Hello Team,
I am trying to update the coverage report for my android project on SonarCloud, but I am not able to do so. Below are the steps for updating the report :
1. Integrate JaCoCo plugin with android project.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.8"
reportsDirectory.set(layout.buildDirectory.dir("jacoco"))
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
reports {
xml.required = true
html.required = true
}
def fileFilter = []
def mainSrc = "${project.projectDir}/src/main/java"
// def javaTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: fileFilter)
def kotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debugUnitTest", excludes: fileFilter)
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([kotlinTree]))
executionData.setFrom(fileTree(dir: "$project.projectDir",
includes: ['**/*.exec', '**/*.ec']
))
}
2. Integrate SonarQube with Android project.
sonarqube {
properties {
property "sonar.organization", "<org_key>"
property "sonar.projectKey", "<prj_key>"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.sources", "src/main/java"
property "sonar.binaries", "build"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.coverage.jacoco.xmlReportPaths", "app/build/jacoco/jacocoTestReport/jacocoTestReport.xml"
property "sonar.tests", ["src/test/java"]
property "sonar.test.inclusions", "**/*Test*/**"
property "sonar.exclusions", '**/com/skydoves/powerspinner/*'
property "sonar.login", "<sonar_token>"
}
}
3. Generate local JaCoCo coverage report using Terminal.
gradlew build jacocoTestReport sonarqube
4. Upload JaCoCo report to SonarCloud using Terminal.
.\gradlew sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=<SONAR_TOKEN>
The coverage report still shows 0.0%, but the JaCoCo coverage report is 86% successful.
Please help me fix this and update the coverage report to SonarCloud.
PS: This is not for the MAIN BRANCH, but for a long-lived branch.
Thank you.