'Unable to get jacoco coverage
I am new to Gradle builds and started implementing CI using Gitlab runner. The jobs work fine and generate the jacoco report as well. However, the report is missing coverage. Console output shows that it skips generating the jacocoTestReport.
Watching 297 directories to track changes
Caching disabled for task ':createDebugAndroidTestCoverageReport' because:
Caching has not been enabled for the task
Task ':createDebugAndroidTestCoverageReport' is not up-to-date because:
No history is available.
> Task :createDebugCoverageReport
Skipping task ':createDebugCoverageReport' as it has no actions.
:createDebugCoverageReport (Thread[Execution worker for ':' Thread 30,5,main]) completed. Took 0.0 secs.
:jacocoTestReport (Thread[Execution worker for ':' Thread 30,5,main]) started.
> Task :jacocoTestReport SKIPPED
Skipping task ':jacocoTestReport' as task onlyIf is false.
Gradle command: gradle testDebug jacocoTestReport
I have added the below content to my build.gradle file for jacoco report and coverage.
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
jacoco {
version = "0.8.7"
}
task jacocoTestReport(type: JacocoReport) {
//group = "Reporting"
dependsOn = ['testDebugUnitTest', 'createDebugCoverageReport']
reports {
html.enabled = true
xml.enabled = true
html.destination file("${buildDir}/jacocoHtml")
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/build/reports", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/location"
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
executionData.from = fileTree(dir: project.buildDir, includes: [
"build/outputs/testDebugUnitTest.exec"
])
}
buildTypes {
release {
minifyEnabled false
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
testImplementation 'junit:junit:4.13.2'
}
Gradle version: 7.0.3
I tried different stack overflow answers and other blogs but still see the same issue. Any inputs would be much helpful. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
