Skip to content

Commit

Permalink
Add own jacoco execution without plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyScherzinger committed Jun 1, 2023
1 parent 86f3bb5 commit 5379c14
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.gradle.internal.jvm.Jvm
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:$androidPluginVersion"
classpath 'com.hiya:jacoco-android:0.2'
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.0"
Expand All @@ -27,7 +26,7 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.hiya.jacoco-android'
apply from: "$rootProject.projectDir/jacoco.gradle"
apply plugin: 'com.github.spotbugs'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'shot'
Expand Down
109 changes: 109 additions & 0 deletions jacoco.gradle
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",
])
}
}

0 comments on commit 5379c14

Please sign in to comment.