Kotlin / kotlinx-kover

Apache License 2.0
1.34k stars 53 forks source link

Exclude classes by path #676

Open friscoMad opened 4 weeks ago

friscoMad commented 4 weeks ago

What is your use-case and why do you need this feature?

We would like to exclude all generated sources from the coverage report/verify rules, we are using dagger that adds some annotations but they don't have BINARY or RUNTIME retention. Source set exclusion does not work for us as Kapt generated sources are included in the main source set. We could use class inheritance to filter some (maybe all) generated classes but it is not working and even when working it adds a time penalty. Adding a feature to exclude from reports/verification based on source path can help excluding all autogenerated classes that are stored in the build directory in gradle it should be efficient and work with most of the code generation tools as they tend to store the generated classes in a different path.

Describe the solution you'd like Add another option to exclude (maybe include) classes by file path, perhaps an exclude dir option or something similar.

shanshin commented 3 weeks ago

Unfortunately, there is a problem with the directory filter, namely, compiled class-files do not store the directory where the source file was located, but only the name of this file.

We can indirectly guess the directory by the package name and the filename from the class-file. However, in general, this does not work, because in Kotlin, the directory name may differ from the package name. Such collisions are poorly detected, so such a filter will be unreliable.

To ensure that the source file directory is analyzed, it is necessary to work at the compiler level. We will be able to implement this after integration with KGP (see #608), because this is a major change that also changes the workflow of Kover.