grzegorz-aniol / junit5-watcher

Junit5 extension for detailed test metrics
Apache License 2.0
5 stars 2 forks source link

Exclude junit dependencies for kotlin-test-junit5 to prevent issues with Gradle #5

Closed jvwilge closed 12 months ago

jvwilge commented 1 year ago

We're running into issues building our Gradle project because we're very strict on version conflicts (we use failOnVersionConflict())

The culprit is kotlin-test-junit5 for including some older junit dependencies (which are already defined in the pom.xml of junit5-watcher-ext. So we're safe to exclude them:

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit5</artifactId>
            <exclusions>
                <!--
                Not excluding org.junit.* causes version conflict in Gradle when using failOnVersionConflict().
                Force use of junit libraries defined in this pom.xml
                -->
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I tried to make a fork, but my machine probably is too slow since the 20% tolerance in the tests is not enough.

grzegorz-aniol commented 1 year ago

Hi @jvwilge, I'm not sure which older junit dependencies you are referencing to.

These are all dependencies of junit5-watcher:

[INFO] pl.appga.junit5:junit5-watcher-ext:jar:1.0
[INFO] +- org.slf4j:slf4j-api:jar:2.0.9:compile
[INFO] +- org.jetbrains.kotlin:kotlin-test-junit5:jar:1.9.10:compile
[INFO] |  \- org.jetbrains.kotlin:kotlin-test:jar:1.9.10:compile
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.10.0:compile
[INFO] |  +- org.opentest4j:opentest4j:jar:1.3.0:compile
[INFO] |  +- org.junit.platform:junit-platform-commons:jar:1.10.0:compile
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.10.0:compile
[INFO] |  \- org.junit.platform:junit-platform-engine:jar:1.10.0:compile
[INFO] +- org.assertj:assertj-core:jar:3.24.2:test
[INFO] |  \- net.bytebuddy:byte-buddy:jar:1.12.21:test
[INFO] +- org.apache.logging.log4j:log4j-slf4j2-impl:jar:2.20.0:test
[INFO] |  +- org.apache.logging.log4j:log4j-api:jar:2.20.0:test
[INFO] |  \- org.apache.logging.log4j:log4j-core:jar:2.20.0:test
[INFO] +- org.junit.jupiter:junit-jupiter-params:jar:5.10.0:test
[INFO] \- org.jetbrains.kotlin:kotlin-reflect:jar:1.9.10:test
[INFO]    \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.9.10:compile
[INFO]       +- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.10:compile
[INFO]       \- org.jetbrains:annotations:jar:13.0:compile
[INFO] 

As you can see kotlin-test-junit5 uses only kotlin-test.

Also JUnit5 version used now is very new one 5.10.0.

If you have some build dependencies problem you can always force to use specific newer version of the module. I'm not sure how it is done with Gradle but in Maven it can be controlled by <dependencyManagement>. In this section you can force to build your project with newer one (assuming there is no any build/runtime conflict).

jvwilge commented 1 year ago

Thanks for the quick reply!

https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-test-junit5/1.9.20/kotlin-test-junit5-1.9.20.pom is using 5.6.3 of both junit libraries. With the strict settings in Gradle this will fail.

Maven will indeed override this version and in Gradle this is also possible, but I think it is nicer if that isn't needed since the libraries are already included in the pom of junit5-watcher with a correct version. Otherwise it would mean including the kotlin-test-junit5 lib and exclude the junit libraries there.

grzegorz-aniol commented 1 year ago

I see, indeed sometimes it's hard to match often used libraries to same version, so either we need upgrade or downgrade. But what you expect to change in junit5-watcher then?

jvwilge commented 1 year ago

It would be nice if the libs are excluded in the pom from kotlin-test-junit5 (so overwrite the dependency definition with what I added in my code sample). This will make it easier for other people to use junit5-watcher in their projects.

grzegorz-aniol commented 12 months ago

Ok, I understand now. I can improve it with the next release. Thanks for the feedback ✋ I didn't find this as a problem, because junit5-watcher uses dependency management itself, and it bumps to newer JUnit5 version and it looks maven dependency tree doesn't show old version used by kotlin-test-junit5 it in the list.

jvwilge commented 12 months ago

Thanks!

Maven kind of hides this. I looked into the why and found out that you can add the -Dverbose flag:

mvn dependency:tree -Dverbose

This will show you where overrides happen. I didn't run into any issues with the other overrides though.

grzegorz-aniol commented 12 months ago

Planned to be release in 1.2 this week

grzegorz-aniol commented 12 months ago

Released in 1.2