-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add own jacoco execution without plugin
see arturdm/jacoco-android-gradle-plugin#102 (comment) Signed-off-by: Andy Scherzinger <[email protected]>
- Loading branch information
1 parent
eb5dc58
commit f186ed7
Showing
2 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
apply plugin: 'jacoco' | ||
|
||
jacoco { | ||
toolVersion = "$jacoco_version" | ||
} | ||
|
||
// Force Jacoco Version | ||
|
||
subprojects { | ||
configurations.all { | ||
resolutionStrategy { | ||
eachDependency { details -> | ||
if ('org.jacoco' == details.requested.group) { | ||
details.useVersion "$jacocoVersion" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
project.afterEvaluate { project -> | ||
|
||
tasks.withType(Test) { | ||
jacoco.includeNoLocationClasses = true | ||
jacoco.excludes = ['jdk.internal.*'] | ||
} | ||
|
||
final flavor = "Gplay" | ||
final buildType = "Debug" | ||
final variant = "$flavor${buildType.capitalize()}" | ||
final taskName = "jacocoTest${variant.capitalize()}UnitTestReport" | ||
|
||
task "$taskName"(type: JacocoReport, dependsOn: "test${variant.capitalize()}UnitTest") { | ||
|
||
reports { | ||
csv.required = false | ||
xml.required = true | ||
html.required = true | ||
} | ||
|
||
final fileFilter = [ | ||
// data binding | ||
'**/databinding/*', | ||
'android/databinding/**/*.class', | ||
'**/android/databinding/*Binding.class', | ||
'**/android/databinding/*', | ||
'**/androidx/databinding/*', | ||
'**/BR.*', | ||
// android | ||
'**/R.class', | ||
'**/R$*.class', | ||
'**/BuildConfig.*', | ||
'**/Manifest*.*', | ||
'**/*Test*.*', | ||
'android/**/*.*', | ||
// kotlin | ||
'**/*MapperImpl*.*', | ||
'**/*$ViewInjector*.*', | ||
'**/*$ViewBinder*.*', | ||
'**/BuildConfig.*', | ||
'**/*Component*.*', | ||
'**/*BR*.*', | ||
'**/Manifest*.*', | ||
'**/*$Lambda$*.*', | ||
'**/*Companion*.*', | ||
'**/*Module*.*', | ||
'**/*Dagger*.*', | ||
'**/*Hilt*.*', | ||
'**/*MembersInjector*.*', | ||
'**/*_MembersInjector.class', | ||
'**/*_Factory*.*', | ||
'**/*_Provide*Factory*.*', | ||
'**/*Extensions*.*', | ||
// sealed and data classes | ||
'**/*$Result.*', | ||
'**/*$Result$*.*', | ||
// adapters generated by moshi | ||
'**/*JsonAdapter.*', | ||
// Hilt | ||
'**/*Module.kt', | ||
'**/di/**', | ||
'dagger.hilt.internal/*', | ||
'hilt_aggregated_deps/*', | ||
|
||
'**/*$Result.*', /* filtering `sealed` and `data` classes */ | ||
'**/*$Result$*.*',/* filtering `sealed` and `data` classes */ | ||
'**/*Args*.*', /* filtering Navigation Component generated classes */ | ||
'**/*Directions*.*', /* filtering Navigation Component generated classes */ | ||
'**/*inlined*.class', /* filtering inlined classes */ | ||
'**/composables/**' | ||
/* INSERT ANY OTHER JUNK YOU WANT FILTERED OUT HERE */ | ||
] | ||
|
||
final androidKotlinTree = fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${variant}", excludes: fileFilter) | ||
final kotlinTree = fileTree(dir: "${project.buildDir}/classes/kotlin/main", excludes: fileFilter) | ||
final javacTree = fileTree(dir: "${project.buildDir}/intermediates/javac/${variant}/classes", excludes: fileFilter) | ||
|
||
final mainSrc = "${project.projectDir}/src/main/java" | ||
final productFlavorSrc = "${project.projectDir}/src/${flavor}/java" | ||
final buildTypeSrc = "${project.projectDir}/src/${buildType}/java" | ||
|
||
sourceDirectories.setFrom files([mainSrc, productFlavorSrc, buildTypeSrc]) | ||
classDirectories.setFrom files([androidKotlinTree, kotlinTree, javacTree]) | ||
executionData.setFrom fileTree(dir: project.buildDir, includes: [ | ||
"jacoco/test${variant.capitalize()}UnitTest.exec", | ||
"outputs/unit_test_code_coverage/${variant}UnitTest/test${variant.capitalize()}UnitTest.exec", | ||
]) | ||
} | ||
} |