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

How to use JUnit 5 and Java 10 in Maven with the confilcting maven-surefire-plugin and org.ow2.asm #1409

Closed
UkonnRa opened this issue May 6, 2018 · 20 comments

Comments

@UkonnRa
Copy link

UkonnRa commented May 6, 2018

In my project I try to use Java 10 with Junit 5, but something interesting occurs.

Background
To make maven work well under Java 10, we need to change the asm library of maven-compiler-plugin to org.ow2.asm. And to make Junit 5 work well under Java 10, we need maven-surefire-plugin. Here is the plugin part of my pom.xml.

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>10</source>
                <release>10</release>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>6.1.1</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>21.1.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>${junit.platform.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>

And when I run run maven's test command in Idea, everything is fine.
But when I run mvn test -f pom.xml -e on the root dir, it gives a error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project user-module: Execution default-test of goal
org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.: IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on proj
ect user-module: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init> (Unknown Source)
    at org.objectweb.asm.ClassReader.<init> (Unknown Source)
    at org.objectweb.asm.ClassReader.<init> (Unknown Source)
    at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse (AsmModuleInfoParser.java:89)
    at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor (AsmModuleInfoParser.java:54)
    at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths (LocationManager.java:83)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.newStartupConfigForModularClasspath (AbstractSurefireMojo.java:1765)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.createStartupConfiguration (AbstractSurefireMojo.java:1708)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.createForkStarter (AbstractSurefireMojo.java:2043)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:1146)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:978)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:854)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

The java.lang.IllegalArgumentException at org.objectweb.asm.ClassReader is really weird, maybe org.ow2.asm is not compatible with maven-surefire-plugin?

Do you guys have any solution? I won't change Java 10 and Junit 5 for some reasons, so don't let me change to Java 8, THX!

@sormuras
Copy link
Member

sormuras commented May 6, 2018

If I traced the call stack correctly, Surefire/Plexus was compiled with asm-6.0_BETA.jar. If I remember correctly, there was a bug or two when it comes to parsing Java 10-compiled class files. There were fixed in ASM 6.1.1, correct @forax?

Somehow, you have to ensure Surefire/Plexus uses the new ASM version too. Which ${surefile.version} do you use, actually?

@sormuras
Copy link
Member

sormuras commented May 6, 2018

@Tibor17 Surefire (master, HEAD) refers to org.codehaus.plexus:plexus-java:jar:0.9.3. Upgrade to 0.9.7? That version refers at least to ASM 6.1 ... better would be a new release referring to ASM 6.1.1. Who can trigger such an update? @rfscholte?

@UkonnRa
Copy link
Author

UkonnRa commented May 6, 2018

@sormuras surefile.version = 2.21.0 and asm.version = 6.1.1, all latest...
So... any solution?

@sormuras
Copy link
Member

sormuras commented May 6, 2018

Mh, perhaps repeat the <!-- Use newer version of ASM --> configuration in the maven-surefire-plugin dependencies section?

@UkonnRa
Copy link
Author

UkonnRa commented May 6, 2018

@sormuras What's your point? I AM USING the latest version of maven-surefire-plugin(2.21.0) and org.ow2.asm(6.1.1), am not I? The key point is the depedency of maven-surefire-plugin, isn't it?

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@sormuras
@rfscholte
We need to create or find same issue in SUREFIRE Jira. Fix it in master branch and hopefully we may have a chance to release surefire version 2.22.0 soon with new JUnit 5 provider under Surefire project.

@sormuras
Copy link
Member

sormuras commented May 6, 2018

[...] The key point is the depedency of maven-surefire-plugin, isn't it?

...and like the maven-compiler-plugin the maven-surefire-plugin ships with a "default" ASM version.

You patched the maven-compiler-plugin.
You didn't patch the maven-surefire-plugin. So it refers to ASM6_BETA (via it's 'plexus-java' dep).

I'm not sure if it works, though.

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@CasterKKK
Try this

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefile.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>${junit.platform.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>${asm.version}</version> <!-- Use newer version of ASM -->
                </dependency>
            </dependencies>
        </plugin>

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@CasterKKK
What version of Maven use use?

@UkonnRa
Copy link
Author

UkonnRa commented May 6, 2018

@Tibor17 maven.version = 3.5.3
In fact, your solution is work. But another problem occurs, and I don't know if I should ask you for help.
In a short word, maven cannot find the test file.

[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ user-module ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[WARNING] Corrupted STDOUT by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file D:\Workspaces\IdeaWorkspace\CasterMovieVertx\user-module\target\surefire-reports\2018-05-06T18-20-20_926-jvmRun1.dumpstream
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 

But in fact, I have several tests in test dir. I doubt if maven-surefire-plugin can find the tests...

And the report is:

# Created on 2018-05-06T18:34:04.409
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'Active code page: 65001'.
java.lang.IllegalArgumentException: Stream stdin corrupted. Expected comma after third character in command 'Active code page: 65001'.
	at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.<init>(ForkClient.java:511)
	at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine(ForkClient.java:209)
	at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:176)
	at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:88)
	at java.base/java.lang.Thread.run(Thread.java:844)

And:

# Created on 2018-05-06T18:34:04.973
May 06, 2018 6:34:04 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable

# Created on 2018-05-06T18:34:04.978
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests

# Created on 2018-05-06T18:34:04.983
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.isNotPrivate(Ljava/lang/reflect/Member;)Z

# Created on 2018-05-06T18:34:04.988
	at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolveContainedMethods(JavaElementsResolver.java:189)

# Created on 2018-05-06T18:34:04.994
	at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolveChildren(JavaElementsResolver.java:177)

# Created on 2018-05-06T18:34:05.000
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)

# Created on 2018-05-06T18:34:05.006
	at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolveClass(JavaElementsResolver.java:61)

# Created on 2018-05-06T18:34:05.011
	at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.lambda$resolve$3(DiscoverySelectorResolver.java:69)

# Created on 2018-05-06T18:34:05.018
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1378)

# Created on 2018-05-06T18:34:05.024
	at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolve(DiscoverySelectorResolver.java:68)

# Created on 2018-05-06T18:34:05.028
	at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:50)

# Created on 2018-05-06T18:34:05.033
	at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61)

# Created on 2018-05-06T18:34:05.038
	at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)

# Created on 2018-05-06T18:34:05.042
	at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)

# Created on 2018-05-06T18:34:05.047
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82)

# Created on 2018-05-06T18:34:05.051
	at org.junit.platform.surefire.provider.TestPlanScannerFilter.accept(TestPlanScannerFilter.java:50)

# Created on 2018-05-06T18:34:05.056
	at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)

# Created on 2018-05-06T18:34:05.061
	at org.junit.platform.surefire.provider.JUnitPlatformProvider.scanClasspath(JUnitPlatformProvider.java:121)

# Created on 2018-05-06T18:34:05.066
	at org.junit.platform.surefire.provider.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:111)

# Created on 2018-05-06T18:34:05.070
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:379)

# Created on 2018-05-06T18:34:05.076
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:340)

# Created on 2018-05-06T18:34:05.081
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)

# Created on 2018-05-06T18:34:05.086
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:413)

# Created on 2018-05-06T18:34:05.091

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@CasterKKK
I think this is issue where Maven uses one version of ASM library and plexus-java another.
Now you should ask Robert Scholte on Maven Mailing List.
You should subscribe to Maven Developers List dev@maven.apache.org and ask directly there if this is workaround is really the way to do it. Not sure if this workaround would be generic solution. Robert knows about this issue but I do not know how far the community goes with generic solution for all plugins and Maven itself.

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@CasterKKK
@sormuras
Not sure about empty test set but it might be caused by corrupted stream as I see.
It can be the same issue of reordering two lines of code:
apache/maven-surefire@5e07379
The point is to call System.setOut() before registering listeners to JUnit which is the above fix.
@sormuras Would it be this issue?

@UkonnRa
Copy link
Author

UkonnRa commented May 6, 2018

@Tibor17
I am afraid I have a different opinion. As you can see in the second report:
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.isNotPrivate(Ljava/lang/reflect/Member;)Z
I think that is because of some methods' missing?

@sormuras
Copy link
Member

sormuras commented May 6, 2018

Which platform and which jupiter version are in play?

@sormuras
Copy link
Member

sormuras commented May 6, 2018

${junit.platform.version} should be 1.2.0
${junit.jupiter.version} should be 5.2.0

@sormuras
Copy link
Member

sormuras commented May 6, 2018

Like shown in the junit5-jupiter-starter-maven: https://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-maven/pom.xml

@Tibor17
Copy link

Tibor17 commented May 6, 2018

@sormuras
I guess @CasterKKK uses some mix of incompatible version of libs or surefire provider, or?

@sormuras
Copy link
Member

sormuras commented May 6, 2018

I guess @CasterKKK uses some mix of incompatible version of libs or surefire provider, or?

Looks like that, aye.

@UkonnRa
Copy link
Author

UkonnRa commented May 6, 2018

In fact, the problem is I didn't add:

<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-params</artifactId>
			<version>${junit.jupiter.version}</version>
			<scope>test</scope>
</dependency>

After adding that everything is fine, thank you guys!

@sormuras
Copy link
Member

sormuras commented May 6, 2018

fyi, https://issues.apache.org/jira/browse/SUREFIRE-1518 was created to update plexus-java in surefire

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants