apps-android-commons/jacoco.gradle
Madhur Gupta b1f06ad9bc
Update jacoco and github actions (#4639)
* Fix jacoco setup

* Fix task name

* Update CI yml file for codecov

* Fix syntax error

* Use all branch instead of just master

* Fix report upload issue

* Remove returnDefaultValues

* Add Github Action and Codecov badge
2021-09-20 22:39:54 +10:00

61 lines
No EOL
1.9 KiB
Groovy

apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.7"
}
android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
project.afterEvaluate {
android.applicationVariants.all { variant ->
def name = variant.name
def testTaskName = "test${name.capitalize()}UnitTest"
tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${name.capitalize()} build."
def fileFilter = ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*']
//java compiled classes
def javaTree = fileTree(
dir: "${buildDir}/intermediates/classes/${name}",
excludes: fileFilter
)
//kotlin compiled classes
def kotlinTree = fileTree(
dir: "${buildDir}/tmp/kotlin-classes/${name}",
excludes: fileFilter
)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([javaTree, kotlinTree]))
executionData.setFrom(fileTree(dir: "${buildDir}", includes: [
"jacoco/${testTaskName}.exec",
"outputs/code-coverage/connected/*coverage.ec"
]))
reports {
xml.enabled = true
html.enabled = true
}
}
}
}