Kotlin / kotlinx-kover

Apache License 2.0
1.25k stars 46 forks source link

Convention plugin + filtering projects #582

Closed igorromcy closed 1 month ago

igorromcy commented 1 month ago

Hey there!

I'm wondering how I should use kover for this case:

I need to configure kover using my convention plugin because I want to run using a filtered list of projects. But looks like we need to configure the main build.gradle file anyway, so I'm not sure how we can avoid configuration conflicts there, is there any default configuration we can leave there to merge all the reports generated by my convention plugin kover configuration? 

this is how I'm using it so far, but I think allProjects won't work the way I need

kover {
    merge {
        allProjects()
        createVariant("coverage") {
            it.addWithDependencies(["fastDebug", "debug"] as String[], true)
        }
    }
}
shanshin commented 1 month ago

Hi, you would like the names of the projects in which you want to apply Kover to be specified in the applied project? Or how do you want to filter projects?

igorromcy commented 1 month ago

I want to filter like you said last week

kover {
    merge {
        allProjects {
            it.path in setOf(":feature:login", ":feature:signup") // or for Groovy  [":feature:login", ":feature:signup"]
        }
    }
}

but the problem is that I still need to configure the main build.gradle file anyway, so I can merge all the filtered projects

shanshin commented 1 month ago

kover { merge { ... DSL it was designed just so that there was no need to create a convention plugin for Kover, and all the settings needed to be specified in only one project.

If, for some reason, it becomes necessary to use a convention plugin, then it is enough to create an project extension to configure this convention plugin.

Example Convention Plugin

interface KoverSettings {
    val projects: ListProperty<String>
}

val settingsExtension = extensions.create<KoverSettings>("koverSettings")

kover {
    merge {
        allProjects {
            it.path in settingsExtension.projects.get()
        }
    }
}

Project (kts)

extensions.configure<My_plugin_gradle.KoverSettings> {
    projects.addAll(":feature:login", ":feature:signup")
}

or Project (Groovy)

koverSettings {
    projects.addAll(":feature:login", ":feature:signup")
}

*name My_plugin_gradle will be different for you and depends on the name of the convention plugin ** it is strictly not recommended to put the configuring of KoverSettings extension in the afterEvaluate block

igorromcy commented 1 month ago

that's great, I could make it works via convention plugin!

I'm now curious about this scenario: I have 2 shards running for example 50 and 100 modules respectively (2 different steps on pipeline)

Is it possible with kover to merge the reports after both executions?

I was trying to do that via the root build.gradle file + convention plugin, but it seems that we have conflicts, is that possible? (my convention plugin doesn't cover the main build.gradle file)

igorromcy commented 1 month ago

In other words, I want to merge all the projects which has coverage file generated (on the main build.gradle file)

shanshin commented 1 month ago

for now the only way is to use koverBinaryReport tasks to generate binary ic report and then merge them by Kover CLI.

shanshin commented 1 month ago

I think you may close this issue and track this, because there will be a discussion of the same question.