Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Exclude io.github.oshai.kotlinlogging Classes from Coverage in Kover 0.9.0 #718

Closed
andreigcraciun opened this issue Dec 17, 2024 · 13 comments
Assignees
Labels
Question Support request issue type S: waiting for clarification Status: additional information required to proceed

Comments

@andreigcraciun
Copy link

andreigcraciun commented Dec 17, 2024

Body:
Hello Kover team,

I’m currently using the kover-maven-plugin (version 0.9.0) and having trouble excluding certain classes/packages from my coverage reports. Specifically, I would like to exclude all classes under the io.github.oshai.kotlinlogging package, as I don’t want my logging code to affect coverage metrics.

private val logger = KotlinLogging.logger {}

What I’ve Tried:
1. Configuring in the plugin configuration to include io.github.oshai.kotlinlogging.**.
2. Trying various patterns and even specifying classes like io.github.oshai.kotlinlogging.KotlinLogging.
3. Running mvn clean verify after each change to ensure changes are picked up.

Despite these attempts, the coverage reports still show the logging classes as partially covered. I’ve reviewed the documentation and previous issues but haven’t found a working solution.

Environment:
• Maven version: 3.9.9
• JDK version: 17
• Kotlin version: 1.9.25
• Kover plugin version: 0.9.0

Questions:
1. Is there a known issue with excluding certain classes or packages in version 0.9.0?
2. Are there recommended patterns or configurations that reliably exclude packages like io.github.oshai.kotlinlogging?

Any guidance or examples would be greatly appreciated. Thank you for your time and help!

@andreigcraciun andreigcraciun added Question Support request issue type S: untriaged Status: issue reported but unprocessed labels Dec 17, 2024
@shanshin
Copy link
Collaborator

Hi,
could you please provide maven configuration with which you performed the filtering

  1. Configuring in the plugin configuration to include io.github.oshai.kotlinlogging.**.

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels Dec 17, 2024
@andreigcraciun
Copy link
Author

<plugins>
                    <plugin>
                        <groupId>org.jetbrains.kotlinx</groupId>
                        <artifactId>kover-maven-plugin</artifactId>
                        <version>0.9.0</version>
                        <configuration>
                            <filters>
                                <excludes>
                                    <classes>
                                        <class>io.github.oshai.kotlinlogging.**</class>
                                    </classes>
                                </excludes>
                            </filters>
                        </configuration>
                        <executions>
                            <!-- instrument test tasks -->
                            <execution>
                                <id>instr</id>
                                <goals>
                                    <goal>instrumentation</goal>
                                </goals>
                            </execution>

                            <!-- generate XML report in verify phase -->
                            <execution>
                                <id>kover-xml</id>
                                <goals>
                                    <goal>report-xml</goal>
                                </goals>
                            </execution>

                            <!-- generate HTML report in verify phase -->
                            <execution>
                                <id>kover-html</id>
                                <goals>
                                    <goal>report-html</goal>
                                </goals>
                            </execution>

                            <!-- check coverage rules in verify phase -->
                            <execution>
                                <id>kover-verify</id>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>

                            <!-- generate IC report -->
                            <execution>
                                <id>kover-ic</id>
                                <goals>
                                    <goal>report-ic</goal>
                                </goals>
                            </execution>

                            <!-- print coverage values to the log -->
                            <execution>
                                <id>kover-log</id>
                                <goals>
                                    <goal>log</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

@shanshin
Copy link
Collaborator

Is changing

                        <configuration>
                            <filters>
                                <excludes>
                                    <classes>
                                        <class>io.github.oshai.kotlinlogging.**</class>
                                    </classes>
                                </excludes>
                            </filters>
                        </configuration>

to

                        <configuration>
                            <filters>
                                <excludes>
                                    <classes>io.github.oshai.kotlinlogging.*</classes>
                                </excludes>
                            </filters>
                        </configuration>

helps?

@andreigcraciun
Copy link
Author

andreigcraciun commented Dec 17, 2024

Ty for your response! But unfortunately it doesn't help. I want to mention that private val logger = KotlinLogging.logger {} is coming from io.github.oshai.kotlinlogging which is an external library. No idea if it matters or not. But whatever I do I can't get 100% coverage because the line val logger = KotlinLogging.logger {} is being market with yellow meaning it's not covered. I am opened to any suggestions.

@shanshin
Copy link
Collaborator

Could you provide a small reproducer project?

@andreigcraciun
Copy link
Author

Sure, thank you so much for your help.

https://github.com/andreigcraciun/kover-kotlinlogging

@shanshin
Copy link
Collaborator

As far as I can see, the classes from the io.github.oshai.kotlinlogging package are not present in the report.
image

Could you clarify what you mean by I would like to exclude all classes under the io.github.oshai.kotlinlogging package?

@andreigcraciun
Copy link
Author

andreigcraciun commented Dec 17, 2024

yes, its not present in the report by itself. but inside digital.cariad.logger -> inside [TestLogger] -> line private val logger = KotlinLogging.logger {} ( which is the class from io.github.oshai.kotlinlogging package ) is not excluded from report. I would love to achieve 100% coverage and I don't know how to exclude that line from the report.
image

@shanshin
Copy link
Collaborator

shanshin commented Dec 17, 2024

The exclusion works on the classes in which the code is called, but not for the classes used (because it is important in which class the executable code was written, and this line is written in the TestLogger class).

In any case, even if you exclude line private val logger = KotlinLogging.logger {}, the constructor of the TestLogger class will remain uncovered (because they work at the same time) - therefore, it is easier to exclude the entire class TestLogger.

@andreigcraciun
Copy link
Author

it is easier to exclude the entire class TestLogger

I understand but because we are talking about a logger, which is present in my whole application, it means I will have to exclude so many classes that it doesn't make sense to generate the report anymore.

What should I do in order to achieve 100% coverage?

@shanshin
Copy link
Collaborator

You can exclude lambda for all logger methods by filter like this:

                <configuration>
                    <filters>
                        <excludes>
                            <classes>*$logger$1</classes>
                        </excludes>
                    </filters>
                </configuration>

@andreigcraciun
Copy link
Author

Thank you for all your help! It was exactly what I looking for! Many thanks <3 !

@andreigcraciun
Copy link
Author

We can close this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Support request issue type S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

No branches or pull requests

2 participants