@@ -13,26 +13,27 @@ import kotlinx.kover.gradle.plugin.dsl.CoverageUnit
1313import kotlinx.kover.gradle.plugin.dsl.GroupingEntityType
1414import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension
1515import kotlinx.kover.gradle.plugin.dsl.KoverVariantCreateConfig
16- import org.gradle.api.Action
1716import org.gradle.api.Project
1817import org.gradle.kotlin.dsl.apply
1918import org.gradle.kotlin.dsl.assign
19+ import org.gradle.kotlin.dsl.configure
20+ import java.io.File
2021
2122enum class KoverVariant (val variantName : String ) {
2223 Presenters (" presenters" ),
2324 States (" states" ),
2425 Views (" views" ),
2526}
2627
27- val koverVariants = KoverVariant .values() .map { it.variantName }
28+ val koverVariants = KoverVariant .entries .map { it.variantName }
2829
2930val localAarProjects = listOf (
3031 " :libraries:rustsdk" ,
3132 " :libraries:textcomposer:lib"
3233)
3334
3435val excludedKoverSubProjects = listOf (
35- " :app " ,
36+ " :appconfig " ,
3637 " :annotations" ,
3738 " :codegen" ,
3839 " :tests:testutils" ,
@@ -42,24 +43,63 @@ val excludedKoverSubProjects = listOf(
4243 " :libraries:core" ,
4344 " :libraries:coroutines" ,
4445 " :libraries:di" ,
46+ " :tests:detekt-rules" ,
47+ " :tests:konsist" ,
48+ " :tests:testutils" ,
4549) + localAarProjects
4650
47- private fun Project.kover (action : Action < KoverProjectExtension > ) {
48- ( this as org.gradle.api.plugins. ExtensionAware ).extensions.configure (" kover" , action )
51+ private fun Project.kover (any : Any ) {
52+ this .dependencies.add (" kover" , any )
4953}
5054
5155fun Project.setupKover () {
56+ // If the project is excluded from Kover, don't apply anything
57+ if (path in excludedKoverSubProjects) return
58+
59+ // Apply the plugin
60+ apply (plugin = " org.jetbrains.kotlinx.kover" )
61+
5262 // Create verify all task joining all existing verification tasks
5363 tasks.register(" koverVerifyAll" ) {
5464 group = " verification"
5565 description = " Verifies the code coverage of all subprojects."
56- val dependencies = listOf (" :app:koverVerifyGplayDebug " ) + koverVariants.map { " :app:koverVerify${it.replaceFirstChar(Char ::titlecase)} " }
66+ val dependencies = listOf (" :koverVerifyMerged " ) + koverVariants.map { " :app:koverVerify${it.replaceFirstChar(Char ::titlecase)} " }
5767 dependsOn(dependencies)
5868 }
5969 // https://kotlin.github.io/kotlinx-kover/
6070 // Run `./gradlew :app:koverHtmlReport` to get report at ./app/build/reports/kover
6171 // Run `./gradlew :app:koverXmlReport` to get XML report
62- kover {
72+ extensions.configure<KoverProjectExtension > {
73+ currentProject {
74+ // Create custom variants for verification
75+ for (variant in koverVariants) {
76+ createVariant(variant) {
77+ defaultVariants(project)
78+
79+ // Using the cache for coverage verification seems to be flaky, so we disable it for now.
80+ val taskName = " koverCachedVerify${variant.replaceFirstChar(Char ::titlecase)} "
81+ val cachedTask = project.tasks.findByName(taskName)
82+ cachedTask?.let {
83+ it.outputs.upToDateWhen { false }
84+ }
85+ }
86+ }
87+
88+ // Create merged variant
89+ createVariant(" merged" ) {
90+ defaultVariants(project)
91+ }
92+ }
93+
94+ // If it's the root project, set up kover for subprojects
95+ if (project.path == " :" ) {
96+ for (project in project.subprojects) {
97+ if (project.path !in excludedKoverSubProjects && File (project.projectDir, " build.gradle.kts" ).exists()) {
98+ kover(project)
99+ }
100+ }
101+ }
102+
63103 reports {
64104 filters {
65105 excludes {
@@ -83,6 +123,10 @@ fun Project.setupKover() {
83123 " io.element.android.libraries.designsystem.theme.components.bottomsheet.*" ,
84124 // Konsist code to make test fails
85125 " io.element.android.tests.konsist.failures" ,
126+ // Previews
127+ " *Preview*Kt" ,
128+ " *PreviewNight*Kt" ,
129+ " *PreviewDay*Kt" ,
86130 )
87131 annotatedBy(
88132 " androidx.compose.ui.tooling.preview.Preview" ,
@@ -194,54 +238,10 @@ fun Project.setupKover() {
194238 }
195239}
196240
197- fun Project.applyKoverPluginToAllSubProjects () = rootProject.subprojects {
198- if (project.path !in localAarProjects) {
199- apply (plugin = " org.jetbrains.kotlinx.kover" )
200- kover {
201- currentProject {
202- for (variant in koverVariants) {
203- createVariant(variant) {
204- defaultVariants(project)
205- }
206- }
207- }
208- }
209-
210- project.afterEvaluate {
211- for (variant in koverVariants) {
212- // Using the cache for coverage verification seems to be flaky, so we disable it for now.
213- val taskName = " koverCachedVerify${variant.replaceFirstChar(Char ::titlecase)} "
214- val cachedTask = project.tasks.findByName(taskName)
215- cachedTask?.let {
216- it.outputs.upToDateWhen { false }
217- }
218- }
219- }
220- }
221- }
222-
223241fun KoverVariantCreateConfig.defaultVariants (project : Project ) {
224- if (project.name == " app" ) {
242+ if (project.path == " : app" ) {
225243 addWithDependencies(" gplayDebug" )
226244 } else {
227245 addWithDependencies(" debug" , " jvm" , optional = true )
228246 }
229247}
230-
231- fun Project.koverSubprojects () = project.rootProject.subprojects
232- .filter {
233- it.project.projectDir.resolve(" build.gradle.kts" ).exists()
234- }
235- .map { it.path }
236- .sorted()
237- .filter {
238- it !in excludedKoverSubProjects
239- }
240-
241- fun Project.koverDependencies () {
242- project.koverSubprojects()
243- .forEach {
244- // println("Add $it to kover")
245- dependencies.add(" kover" , project(it))
246- }
247- }
0 commit comments