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

STS 4.6.0 Eclipse - Springboot 2.2.5 - JUnit5 failing (NoClassDefFoundError) #431

Closed
lneumeier opened this issue Mar 25, 2020 · 8 comments
Closed

Comments

@lneumeier
Copy link

Hello,

Launching tests with JUnit5 fails for springboot applications (2.2.5).

Reason:
Eclipse 4.15 ships with JUnit5 5.6.0
Springboot 2.2.5 uses JUnit5 5.5.2 (https://github.com/spring-projects/spring-boot/blob/2.2.x/spring-boot-project/spring-boot-dependencies/pom.xml)

Result:

java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineDiscoveryListener
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.getLauncherDiscoveryListener(LauncherDiscoveryRequestBuilder.java:241)
	at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.build(LauncherDiscoveryRequestBuilder.java:235)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.EngineDiscoveryListener
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 18 more

Solution/Workaround:

adding/updating Junit5 version to 5.6.0 in build.gradle:

ext['junit-jupiter.version'] = '5.6.0'

I think that a warning on the download page would be nice until springboot updates their dependencies to JUnit5 5.6.0.

@martinlippert martinlippert transferred this issue from spring-attic/spring-ide Mar 27, 2020
@martinlippert martinlippert added this to the 4.6.1.RELEASE milestone Mar 27, 2020
@martinlippert
Copy link
Member

We should discuss with the Eclipse team that works on the JUnit integration what the proposed solution is for projects that do not use the exact same version of JUnit5 than the IDE. I think this is a quite common case and many people will hit this.

@martinlippert
Copy link
Member

(oh, and I moved this issue to the Spring Tools 4 project, just for your notice)

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Alex Boyko:)

Seems like a problem in Buildship Gradle plugin... If I try the same Maven project with the same dependencies created by Initializr it launches fine and has 5.5.2 JUnit on the classpath... Therefore, seems like something is off with the Eclipse project produced by Buildship Gradle...

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Alex Boyko:)

Not sure what's wrong... Probably has to do with the classpath calculated in the launch config by the JDT based on the info in the project... Think this is something to figure out on the Buildship Gradle side hence i raised:
eclipse/buildship#980

@lneumeier
Copy link
Author

lneumeier commented Mar 27, 2020

Another solution is, adding
testImplementation 'org.junit.platform:junit-platform-launcher'
instead of
ext['junit-jupiter.version'] = '5.6.0'
to build.gradle.

@martinlippert
Thank you for moving this issue to the right project.

de-jcup added a commit to mercedes-benz/sechub that referenced this issue Jul 2, 2020
- do now provide a test PDS inside sechub-integration test project
  which is automatically started and stopped in task integration test
- also fixes problem with eclipse-2020-06 by adding
  dependency to correct junit-platform runner library
  see spring-projects/sts4#431
- removed some unnecessary profiles
- integration test and dev profile do now work "out-of-the-Box"
@jjohannes
Copy link

Instead of testImplementation 'org.junit.platform:junit-platform-launcher', you can also use testRuntimeOnly 'org.junit.platform:junit-platform-launcher' to keep this away from your compile classpath.

Also note that this is only a forward compatibility issue (the tool uses a newer version than the build). I confirmed with the JUnit team that backward compatibility (the build uses a newer version than the tool) should be guaranteed.

Some more details: eclipse/buildship#980 (comment)

@dsjtlmy
Copy link

dsjtlmy commented Sep 26, 2020

我使用使用相同的Eclipse,在一台电脑上可以执行 Junit5 ,另一台电脑上就报错,很奇怪。
Eclipse IDE for Enterprise Java Developers.
Version: 2020-03 (4.15.0)
Build id: 20200313-1211

junit-jupiter 插件版本是 5.6.0

@martinlippert
Copy link
Member

I am closing this one here as a duplicate of the mentioned buildship issue: eclipse/buildship#980. Please feel free to comment if you think we need to keep this open and investigate this further from the Spring Tools side and we can re-open the issue for that, if necessary.

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

5 participants