From f186ed7ac5f8e94cba3e564b0d8a36695f44e6b2 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 8 May 2023 19:06:33 +0200 Subject: [PATCH] Add own jacoco execution without plugin see https://github.com/arturdm/jacoco-android-gradle-plugin/issues/102#issuecomment-1529324972 Signed-off-by: Andy Scherzinger --- app/build.gradle | 3 +- jacoco.gradle | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 jacoco.gradle diff --git a/app/build.gradle b/app/build.gradle index a6b731f1cf0e..02426fc5af45 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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.22.0" @@ -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' diff --git a/jacoco.gradle b/jacoco.gradle new file mode 100644 index 000000000000..bd50ccf3b275 --- /dev/null +++ b/jacoco.gradle @@ -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", + ]) + } +}