org.gradle.api.internal.tasks.testing.TestSuiteExecutionException:无法完成 Gradle 的执行

问题描述 投票:0回答:1

在 Spring Boot 升级 3.4.0 期间,我遇到了以下错误,该错误实际上在 3.3.6 中运行良好。

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 20.
   at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:64)
   at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
   at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
   at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
   at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
   at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
   at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
   at jdk.proxy2/jdk.proxy2.$Proxy5.stop(Unknown Source)
   at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
   at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
   at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
   at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
   at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
   at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
   at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
   at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
   at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) Caused by: java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
   at java.base/java.lang.ClassLoader.defineClass1(Native Method)
   at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
   at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
   at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
   at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
   at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
   at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
   at java.base/java.lang.Class.forName0(Native Method)
   at java.base/java.lang.Class.forName(Class.java:467)
   at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1217)
   at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
   at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
   at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
   at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
   at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
   at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
   at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
   at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
   at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
   at org.junit.platform.launcher.core.LauncherFactory.registerTestExecutionListeners(LauncherFactory.java:179)
   at org.junit.platform.launcher.core.LauncherFactory.createDefaultLauncher(LauncherFactory.java:137)
   at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:125)
   at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:109)
   at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
   at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
   at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
   at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
   ... 18 more Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
   at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
   at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
   ... 50 more

请在下面找到依赖项详细信息

   dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:3.3.6")
        classpath 'org.owasp:dependency-check-gradle:8.2.1'
    }    //Testing
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation("org.junit.jupiter:junit-jupiter")
}

在父 build.gradle 文件中将 spring boot 版本升级到 3.4.0 时,测试用例无法针对其中一个依赖服务运行,如何解决此问题。

spring-boot testing junit noclassdeffounderror classnotfound
1个回答
0
投票

我遇到了这个问题,并使用 Spring Initializer for version 3.4 Java 17 创建了一个简单的 Spring Boot 3.4 项目,并注意到它包含此测试运行时依赖项:

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

我将其包含在我的项目中,然后它能够找到丢失的类,并且我的测试开始执行

© www.soinside.com 2019 - 2024. All rights reserved.