Kotlin / kotlinx-kover

Apache License 2.0
1.27k stars 47 forks source link

koverVerify and koverXmlReport usage with 0.7.0-Alpha plugin version #389

Closed alessandro-violante closed 12 months ago

alessandro-violante commented 1 year ago

Hi, today in my project I've updated the version of the plugin from 0.5.0 version to 0.7.0-Alpha version because in my project I use several variants and I would have liked to generate the report only for one of them.

The command gradle tasks returns me the tasks "koverXmlReport" and "koverVerify" for all the single variants and environments as expected, but I'm encountering problems with the compilation of my old code and I can't find how to fix them.

I've already tried the code shown here, but in my project my build.gradle files are not .kts files. They're just build.gradle (.gradle files), so this code doesn't work for me and it seems that the new tasks (koverVerifyDevVariantNameDebug and koverXmlReportDevVariantNameDebug) can't be used anymore as shown there).

That's the code:

tasks.koverVerifyDevVariantNameDebug { rule { name = "Minimal line coverage rate in percents" bound { minValue = 33 } } excludes = ['*.json', '**/*test*/**'] }

tasks.koverXmlReportDevVariantNameDebug { excludes = ['*.json', '**/*test*/**'] }

The tasks "koverVerifyDevVariantNameDebug" and "koverXmlReportDevVariantNameDebug" exist, but it seems they don't have to be implemented in this way anymore.

Could you please write me an example of how should they be written now?

Thanks a lot in advance.

alessandro-violante commented 1 year ago

In the meanwhile, I've done some attempts on my own.

Picture 1: Picture1

Picture 2: Picture2

shanshin commented 1 year ago

Hi, could you clarify why you are using the 0.7.0-Alpha version instead of 0.7.0?

but in my project my build.gradle files are not .kts files. They're just build.gradle (.gradle files), so this code doesn't work for me

Examples of kover and koverReport block settings work unchanged for both build.gradle and build.gradle.kts files.

In version 0.7.x, all Kover plugin settings occur only in extensions kover and koverReport, so there is no need to configure Kover Gradle tasks.

I've edited the exclusions configuration code changing "koverReport" with "koverXmlReportDebug", as "koverReport" doesn't exist anymore in the tasks list

koverReport - is not the name of the task, it is an extension of the project that is used to configure all Kover reports.

Please also refer to the documentation for using the plugin.

alessandro-violante commented 1 year ago

Hi,

Thanks for the explanation.

The reason why I'm trying to use the 0.7.0-Alpha version is that in my project I have a lot of flavors and it takes me a lot of time to generate the Kover report for all of them (about 1 hour).

I've seen that in 0.7.0-Alpha version there are specific Gradle tasks available for each flavor (for example: "koverReportDevVariantNameDebug"). I've tried to generate the report with that Kover version and that specific Gradle task and without any additional configuration (i.e. build.gradle koverReport exclusions and so on) and I've generated the report in about 15 seconds.

It's great for me, but I necessarily have to filter the report so that some files are excluded, so I necessarily have to configure "koverReport" in my build.gradle file to exclude some folders and files.

The problem is that, if as you say I use "koverReport" as described in the example file and I execute the "gradlew" task, I get the error I attach you in Picture 1:

Picture_1-0 7 0-Alpha

It seems like in 0.7.0-Alpha version the configuration should be different, as the error reports that the method androidReports() can't be found.

How should I configure "koverReport" using 0.7.0-Alpha version?

Best regards

shanshin commented 1 year ago

It seems like in 0.7.0-Alpha version the configuration should be different, as the error reports that the method androidReports() can't be found.

Yes, because the documentation is for the latest version - 0.7.0

I've seen that in 0.7.0-Alpha version there are specific Gradle tasks available for each flavor

Version 0.7.0 works the same way.

It's great for me, but I necessarily have to filter the report so that some files are excluded

The easiest way is to add filters for all build variants:

koverReport {
    filters {
        excludes {
            classes("some.packg.FqClassN*",  "*.Class2")
        }
    }
}

However, please note, due to technical limitations, Kover can filter only by class names,  but not by file names, directories, as well as directory separators - it is not allowed. Also see

alessandro-violante commented 1 year ago

Hi,

Thanks for the explanation.

Now I'm using 0.7.0 version of the plugin, but when building my project I'm encountering the error I attach you in Picture 1:

Picture1

I also attach you my build.gradle and app/build.gradle files.

build.gradle build.gradle.txt

app/build.gradle app-build.gradle.txt

They seem quite similar to those contained in the example project, and I can't understand what the problem could be.

Let me know if you also need settings.gradle and gradle.properties. They're very similar to those used in the example.

Thanks a lot in advance:

shanshin commented 1 year ago

Please, try version 0.7.1 - it should solve the problem with org/gradle/configurationcache/extensions/CharSequenceExtensionsKt

alessandro-violante commented 1 year ago

Hi!

Yes, thank you, 0.7.1 has fixed the problem, but as you can see in the attachment, I don't see the tasks differentiated by flavor.

Version 0.7.1 kover-0 7 1

In the tasks list I don't see the feature "Added support of Android build variants". Am I doing something wrong?

Could you please check?

Best regards

shanshin commented 1 year ago

The tasks shown in the screenshot are missing in version 0.7.1. Please recheck the correctness of the version, you may have specified 0.6.1

alessandro-violante commented 12 months ago

Thank you! I've solved my problem.