maven-surefire icon indicating copy to clipboard operation
maven-surefire copied to clipboard

Compatibility with Jupiter 6.0.0+

Open mxcross opened this issue 1 month ago • 10 comments

New feature, improvement proposal

junit-jupiter-api now has 6.0.0 and 6.0.1 available. I'm unable to use the latest version of junit because maven-surefire is unable to execute tests with the upgrade. It continues to load the 1.12.1 platform launcher causing conflicts with the desired platform launcher. Ignoring the system classloader and the maven classloader doesn't change the behavior.

mxcross avatar Nov 06 '25 20:11 mxcross

What we have to keep in mind: JUnit 6 requires Java 17, so if we ship things of it, it can only be done in Maven 4 version of the plugin

Bukama avatar Nov 07 '25 07:11 Bukama

Should be works, can create a simple reproduce project?

slawekjaranowski avatar Nov 07 '25 07:11 slawekjaranowski

Please also look at:

  • https://github.com/apache/maven-surefire/issues/850

slawekjaranowski avatar Nov 07 '25 07:11 slawekjaranowski

you should be able to override the dependency by adding it in the dependencies section of the plugin itself.

olamy avatar Nov 07 '25 07:11 olamy

@olamy that is the first thing I tried. Something about the loading of the classpath completely ignored the version of JUnit I was setting and always got the version the plugin is compiled with. I think the main issue is there is an incompatibility between a call surefire is making and the changes made to junit in the new version.

[2025-11-06T15:12:36.038Z] [ERROR] java.lang.NoSuchMethodError: 'java.util.stream.Collector org.junit.platform.commons.util.CollectionUtils.toUnmodifiableList()'

[2025-11-06T15:12:36.038Z] [ERROR] org.apache.maven.surefire.api.util.SurefireReflectionException: java.lang.NoSuchMethodError: 'java.util.stream.Collector org.junit.platform.commons.util.CollectionUtils.toUnmodifiableList()'

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.api.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:107)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.createProviderInCurrentClassloader(ForkedBooter.java:449)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

[2025-11-06T15:12:36.038Z] [ERROR] Caused by: java.lang.NoSuchMethodError: 'java.util.stream.Collector org.junit.platform.commons.util.CollectionUtils.toUnmodifiableList()'

[2025-11-06T15:12:36.038Z] [ERROR] at org.junit.platform.launcher.TagFilter.parseAll(TagFilter.java:176)

[2025-11-06T15:12:36.038Z] [ERROR] at org.junit.platform.launcher.TagFilter.includeMatching(TagFilter.java:133)

[2025-11-06T15:12:36.038Z] [ERROR] at org.junit.platform.launcher.TagFilter.includeTags(TagFilter.java:89)

[2025-11-06T15:12:36.038Z] [ERROR] at java.base/java.util.Optional.map(Optional.java:260)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.newFilters(JUnitPlatformProvider.java:229)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.(JUnitPlatformProvider.java:104)

[2025-11-06T15:12:36.038Z] [ERROR] at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.(JUnitPlatformProvider.java:98)

[2025-11-06T15:12:36.038Z] [ERROR] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

[2025-11-06T15:12:36.039Z] [ERROR] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)

[2025-11-06T15:12:36.039Z] [ERROR] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

[2025-11-06T15:12:36.039Z] [ERROR] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

[2025-11-06T15:12:36.039Z] [ERROR] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

[2025-11-06T15:12:36.039Z] [ERROR] at org.apache.maven.surefire.api.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:105)

[2025-11-06T15:12:36.039Z] [ERROR] ... 5 more

mxcross avatar Nov 07 '25 13:11 mxcross

It's like guessing what numbers were used to sum to 10.

@mxcross Could you show your 5 and 4?

pzygielo avatar Nov 07 '25 14:11 pzygielo

I have 0 junit 4 tests, this is ensured by the maven-enforcer-plugin. Everything in my setup is set to use the jupiter 6.0.0 version, which is how I start to see the error. It's a massive repository that I'm not able to share with the public.

mvn dependency:tree also confirms all of my imports are on jupiter 6.0.0.

mxcross avatar Nov 07 '25 14:11 mxcross

By 5 and 4 I meant the numbers to sum to get 10.

It's a massive repository that I'm not able to share with the public.

Don't. Prepare reproducer to show the problem reported.

pzygielo avatar Nov 07 '25 14:11 pzygielo

I'm unable to use the latest version of junit because maven-surefire is unable to execute tests with the upgrade.

I'm able and I see no issue with JUnit 6.0.x.

pzygielo avatar Nov 07 '25 14:11 pzygielo

Seering as I opened it as an enhancement request, it doesn't seem unreasonable to ask that a new 4.x version of the plugin be compiled with the latest junit apis.

mxcross avatar Nov 07 '25 14:11 mxcross

@mxcross can you provide a simple project which reproduce your issue?

slawekjaranowski avatar Dec 18 '25 08:12 slawekjaranowski

yup need a reproducer as it works fine for such large project https://github.com/jetty/jetty.project/pull/14027

olamy avatar Dec 18 '25 08:12 olamy