From 93764e0941a3baa5447710297f5b23bf4e8b1858 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 9 Jan 2024 12:53:29 +0100 Subject: [PATCH 1/5] build: introduce Kover Gradle plugin To combine Android and JVM projects, an additional configuration in root project was needed. Please see: - https://github.com/Kotlin/kotlinx-kover/issues/522#issuecomment-1873931512 - https://github.com/Kotlin/kotlinx-kover/issues/509#issuecomment-1830635724 --- WordPress/build.gradle | 7 +++++++ build.gradle | 8 ++++++++ libs/editor/build.gradle | 7 +++++++ libs/image-editor/build.gradle | 7 +++++++ libs/processors/build.gradle | 1 + settings.gradle | 2 ++ 6 files changed, 32 insertions(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index bb75f28e5ff4..2330052a1794 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -12,6 +12,13 @@ plugins { id "se.bjurr.violations.violation-comments-to-github-gradle-plugin" id "com.google.gms.google-services" id 'dagger.hilt.android.plugin' + id "org.jetbrains.kotlinx.kover" +} + +koverReport { + defaults { + mergeWith("wordpressWasabiDebug") + } } sentry { diff --git a/build.gradle b/build.gradle index 773555a2d729..364eb35fe24c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id "io.gitlab.arturbosch.detekt" id 'com.automattic.android.measure-builds' + id "org.jetbrains.kotlinx.kover" id "androidx.navigation.safeargs.kotlin" apply false id "com.android.library" apply false id 'com.google.gms.google-services' apply false @@ -246,6 +247,13 @@ tasks.register("configureApply") { dependencies { detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$gradle.ext.detektVersion" + + kover( + project(":WordPress"), + project(":libs:editor"), + project(":libs:image-editor"), + project(":libs:processors"), + ) } apply from: './config/gradle/gradle_build_scan.gradle' diff --git a/libs/editor/build.gradle b/libs/editor/build.gradle index b6323f01d4c0..749cd569bf6f 100644 --- a/libs/editor/build.gradle +++ b/libs/editor/build.gradle @@ -2,6 +2,13 @@ plugins { id "com.android.library" id "org.jetbrains.kotlin.android" id "org.jetbrains.kotlin.plugin.parcelize" + id "org.jetbrains.kotlinx.kover" +} + +koverReport { + defaults { + mergeWith("debug") + } } repositories { diff --git a/libs/image-editor/build.gradle b/libs/image-editor/build.gradle index 21fbf110e765..8dba0316fa67 100644 --- a/libs/image-editor/build.gradle +++ b/libs/image-editor/build.gradle @@ -3,6 +3,13 @@ plugins { id "org.jetbrains.kotlin.android" id "org.jetbrains.kotlin.plugin.parcelize" id "androidx.navigation.safeargs.kotlin" + id "org.jetbrains.kotlinx.kover" +} + +koverReport { + defaults { + mergeWith("debug") + } } android { diff --git a/libs/processors/build.gradle b/libs/processors/build.gradle index 03b3715127f0..8e338bd2ea76 100644 --- a/libs/processors/build.gradle +++ b/libs/processors/build.gradle @@ -1,6 +1,7 @@ plugins { id "org.jetbrains.kotlin.jvm" id "org.jetbrains.kotlin.kapt" + id "org.jetbrains.kotlinx.kover" } sourceCompatibility = JavaVersion.VERSION_1_8 diff --git a/settings.gradle b/settings.gradle index 5ce20fe7d7ed..5e48b42287db 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,6 +8,7 @@ pluginManagement { gradle.ext.detektVersion = '1.23.0' gradle.ext.violationCommentsVersion = '1.67' gradle.ext.measureBuildsVersion = '2.0.3' + gradle.ext.koverVersion = '0.7.5' plugins { id "org.jetbrains.kotlin.android" version gradle.ext.kotlinVersion @@ -24,6 +25,7 @@ pluginManagement { id "io.gitlab.arturbosch.detekt" version gradle.ext.detektVersion id "se.bjurr.violations.violation-comments-to-github-gradle-plugin" version gradle.ext.violationCommentsVersion id 'com.automattic.android.measure-builds' version gradle.ext.measureBuildsVersion + id "org.jetbrains.kotlinx.kover" version gradle.ext.koverVersion } repositories { maven { From 9170a445efb11879e654959a7db1461fee9661f3 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 9 Jan 2024 13:21:13 +0100 Subject: [PATCH 2/5] style: extract code coverage configuration To a separate script plugin, to keep all code coverage configuration in a single place --- WordPress/build.gradle | 6 ------ build.gradle | 8 +------- config/gradle/code_coverage.gradle | 28 ++++++++++++++++++++++++++++ libs/editor/build.gradle | 6 ------ libs/image-editor/build.gradle | 6 ------ 5 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 config/gradle/code_coverage.gradle diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 2330052a1794..de2aad4a6ac1 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -15,12 +15,6 @@ plugins { id "org.jetbrains.kotlinx.kover" } -koverReport { - defaults { - mergeWith("wordpressWasabiDebug") - } -} - sentry { tracingInstrumentation { enabled = true diff --git a/build.gradle b/build.gradle index 364eb35fe24c..e57b95f0e5a8 100644 --- a/build.gradle +++ b/build.gradle @@ -247,13 +247,7 @@ tasks.register("configureApply") { dependencies { detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$gradle.ext.detektVersion" - - kover( - project(":WordPress"), - project(":libs:editor"), - project(":libs:image-editor"), - project(":libs:processors"), - ) } +apply from: './config/gradle/code_coverage.gradle' apply from: './config/gradle/gradle_build_scan.gradle' diff --git a/config/gradle/code_coverage.gradle b/config/gradle/code_coverage.gradle new file mode 100644 index 000000000000..b66d4bf7981d --- /dev/null +++ b/config/gradle/code_coverage.gradle @@ -0,0 +1,28 @@ +static String resolveProjectVariantForCodeCoverage(Project project) { + if (project.name == "WordPress") { + return "wordpressWasabiDebug" + } else { + return "debug" + } +} + +subprojects { + pluginManager.withPlugin("org.jetbrains.kotlinx.kover") { + if (project.plugins.hasPlugin("com.android.library") || project.plugins.hasPlugin("com.android.application")) { + koverReport { + defaults { + mergeWith(resolveProjectVariantForCodeCoverage(project)) + } + } + } + } +} + +dependencies { + kover( + project(":WordPress"), + project(":libs:editor"), + project(":libs:image-editor"), + project(":libs:processors"), + ) +} diff --git a/libs/editor/build.gradle b/libs/editor/build.gradle index 749cd569bf6f..a6203ef1c9ed 100644 --- a/libs/editor/build.gradle +++ b/libs/editor/build.gradle @@ -5,12 +5,6 @@ plugins { id "org.jetbrains.kotlinx.kover" } -koverReport { - defaults { - mergeWith("debug") - } -} - repositories { maven { url "https://a8c-libs.s3.amazonaws.com/android" diff --git a/libs/image-editor/build.gradle b/libs/image-editor/build.gradle index 8dba0316fa67..2cdd7f6bf40f 100644 --- a/libs/image-editor/build.gradle +++ b/libs/image-editor/build.gradle @@ -6,12 +6,6 @@ plugins { id "org.jetbrains.kotlinx.kover" } -koverReport { - defaults { - mergeWith("debug") - } -} - android { namespace "org.wordpress.android.imageeditor" From 6b27b091670c30be212454cac4bc0fbf520093f9 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 9 Jan 2024 16:10:57 +0100 Subject: [PATCH 3/5] build: add code coverage exclusions --- config/gradle/code_coverage.gradle | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/config/gradle/code_coverage.gradle b/config/gradle/code_coverage.gradle index b66d4bf7981d..ad131844a983 100644 --- a/config/gradle/code_coverage.gradle +++ b/config/gradle/code_coverage.gradle @@ -26,3 +26,43 @@ dependencies { project(":libs:processors"), ) } + +koverReport { + filters { + excludes { + packages( + 'com.bumptech.glide', + 'dagger.*', + '*.compose*', + '*.debug*', + 'hilt_aggregated_deps', + '*.databinding', + 'org.wordpress.android.widgets' + ) + + classes( + '*_Factory*', + '*Activity', + '*Activity$*', + '*Adapter', + '*Adapter$*', + '*BuildConfig', + '*DiffCallback*', + '*Dialog', + '*Dialog$*', + '*Fragment', + '*Fragment$*', + '*FragmentDirections*', + '*FragmentKt*', + '*View', + '*View$*', + '*ViewHolder', + '*ViewHolder$*', + '*ViewHolderKt*', + '*.Hilt_*', + '*HiltModules*', + '*_MembersInjector' + ) + } + } +} From 9564e57951ffa94b81caade2b0baae7f97c280ef Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 9 Jan 2024 16:40:25 +0100 Subject: [PATCH 4/5] build: exclude Hilt modules --- config/gradle/code_coverage.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/gradle/code_coverage.gradle b/config/gradle/code_coverage.gradle index ad131844a983..ad528328d329 100644 --- a/config/gradle/code_coverage.gradle +++ b/config/gradle/code_coverage.gradle @@ -37,7 +37,8 @@ koverReport { '*.debug*', 'hilt_aggregated_deps', '*.databinding', - 'org.wordpress.android.widgets' + 'org.wordpress.android.modules', + 'org.wordpress.android.widgets', ) classes( @@ -54,6 +55,8 @@ koverReport { '*Fragment$*', '*FragmentDirections*', '*FragmentKt*', + '*Module', + '*Module_*', '*View', '*View$*', '*ViewHolder', @@ -61,7 +64,7 @@ koverReport { '*ViewHolderKt*', '*.Hilt_*', '*HiltModules*', - '*_MembersInjector' + '*_MembersInjector', ) } } From a9c5988933eda95626feef046f65d5d542f84e4a Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Tue, 9 Jan 2024 17:39:14 +0100 Subject: [PATCH 5/5] build: use release variants when generating code coverage All unit tests executed on CI are currently executed on release/vanillRelease variants, hence the alignment. --- config/gradle/code_coverage.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/gradle/code_coverage.gradle b/config/gradle/code_coverage.gradle index ad528328d329..6ffe328b90ba 100644 --- a/config/gradle/code_coverage.gradle +++ b/config/gradle/code_coverage.gradle @@ -1,8 +1,8 @@ static String resolveProjectVariantForCodeCoverage(Project project) { if (project.name == "WordPress") { - return "wordpressWasabiDebug" + return "wordpressVanillaRelease" } else { - return "debug" + return "release" } }