Failed to execute junit5 tests with dependency management with spring boot gradle plugin - spring-boot

In my project based on gradle and kotlin I have some sub module. Build configugration for it module (build.gradle.kts):
plugins {
java
kotlin("jvm")
id("org.springframework.boot") version "2.1.5.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
}
dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.31")
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.31")
testCompile("org.jetbrains.kotlin:kotlin-stdlib:1.3.31")
testCompile("org.jetbrains.kotlin:kotlin-reflect:1.3.31")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
I try to run some simple test in this module
Simple class:
class Hello {
fun hello(): String {
return "hello"
}
}
Simple test for it:
class HelloTest {
#Test
fun test() {
Assertions.assertEquals(Hello().hello(), "hello")
}
}
When i'm trying to run test i get error:
Jun 12, 2019 2:58:31 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to execute tests
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(Ljava/lang/String;)Lorg/junit/platform/commons/function/Try;
at org.junit.jupiter.engine.support.OpenTest4JAndJUnit4AwareThrowableCollector.createAbortedExecutionPredicate(OpenTest4JAndJUnit4AwareThrowableCollector.java:40)
at org.junit.jupiter.engine.support.OpenTest4JAndJUnit4AwareThrowableCollector.<clinit>(OpenTest4JAndJUnit4AwareThrowableCollector.java:30)
at org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector(JupiterThrowableCollectorFactory.java:34)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:68)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:rest:test'.
> No tests found for given includes: [ua.company.app.Hello](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
4 actionable tasks: 2 executed, 2 up-to-date
No tests found for given includes: [ua.company.app.Hello](filter.includeTestsMatching)
But if remove id("io.spring.dependency-management") version "1.0.7.RELEASE" from my build config and will use version of spring boot like this compile("org.springframework.boot:spring-boot-starter-web:2.1.5.RELEASE") test runs correctly.
Spring dependency management brokes my junit5 tests. Please can anyone explain why this is happening and how to solve the problem? Thanks!

It would appear that adding Spring Dependency Management changes some of the transitive dependencies for your junit-jupiter dependencies.
Your declared junit version (5.4.2) depends on junit-platform-commons 1.4.2, but when you add Spring Dependency Management it is changing the commons version from 1.4.2 to 1.3.2. This is why you are receiving the NoSuchMethodError since that method was added in version four!
Here's two solutions I can think of:
1) (I recommend this) Drop your declared junit version and let Spring Dependency Management handle everything for junit:
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntime("org.junit.jupiter:junit-jupiter-engine")
2) Declare the transitive dependency versions for junit (this would allow you to carry on using version 5.4.2 if this is a must-have)
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.2")
testImplementation("org.junit.platform:junit-platform-commons:1.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
testRuntime("org.junit.platform:junit-platform-engine:1.4.2")

Related

Spring Boot 1 and Gradle: ClassNotFoundException SpringApplicationBuilder

I've got a Gradle configuration for a Spring Boot 1.5 application. It runs fine in Spring Tool Suite, but gradlew build creates a jar file with no jar files in the BOOT-INF folder. This of course prevents the successful execution of the jar file:
java -jar build\libs\myapp-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/builder/SpringApplicationBuilder
at myapp.boot.Application.runWithContextHierarchy(Application.java:50)
at myapp.boot.Application.main(Application.java:33)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.builder.SpringApplicationBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more
build.gradle excerpt:
plugins {
id 'org.springframework.boot' version '1.5.22.RELEASE'
id 'java'
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
...
}
Turns out that Spring Boot 1 isn't able to work with implementation dependencies, but with (deprecated) compile dependencies.
Working build.gradle dependencies:
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
....
}

Where in SpringHow in Spring Boot do I solve a "java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext"?

I"m using Java 8 and Spring Boot. Trying to build a simple REST application that sits on a MongoDB. I have this in my Gradle build file
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web:2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-dependencies:2.1.5.RELEASE'
}
but when I go to start my app I get an error about not being able to find a class, "org/springframework/data/mapping/context/MappingContext":
localhost:todoapp-backend davea$ java -jar ./build/libs/spring-data-mongodb-example-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/data/mapping/context/MappingContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.context.MappingContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
What other dependency I'm I supposed to include to get the missing class found?
You should use Springboot Gradle plugin. It will solve all your dependecies issues .
plugins {
id 'java
id 'org.springframework.boot' version '2.1.5.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
}

How do I add dependencies to my custom Gradle plugin?

I get a NoClassDefFoundError when trying to add a dependency to my custom Gradle plugin, and I haven't found a way to solve it.
Added to the plugin's dependency block:
implementation("org.apache.logging.log4j:log4j-api:2.11.2")
implementation("org.apache.logging.log4j:log4j-core:2.11.2")
Added to the plugin's DeclarationAttributeAltererExtension implementation:
val log = LogManager.getLogger(ReallyAllOpenExtension::class.java)
Here's the full stacktrace:
no.synth.kotlin.plugins.reallyallopen.FunctionalPluginTest > should include plugin via plugins block FAILED
org.gradle.testkit.runner.UnexpectedBuildFailure: Unexpected build execution failure in /var/folders/g4/024g2mzn7jl5s2b2cvg_ythh00016k/T/junit5022572406008108408 with arguments [build]
Output:
> Task :compileKotlin FAILED
e: java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at no.synth.kotlin.plugins.reallyallopen.ReallyAllOpenExtension.<clinit>(ReallyAllOpenPlugin.kt:106)
at no.synth.kotlin.plugins.reallyallopen.ReallyAllOpenRegistrar.registerProjectComponents(ReallyAllOpenPlugin.kt:79)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:174)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:123)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:413)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:259)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:124)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:54)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:103)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:364)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:237)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:79)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:91)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:597)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:102)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:455)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1023)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1065)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1022)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:454)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 44 more
The full implementation and test case is in a separate branch at https://github.com/henrik242/kotlin-really-allopen/tree/unable-to-add-dependencies
Recreate the problem by running ./gradlew clean :kotlin-really-allopen:build :kotlin-really-allopen:publishToMavenLocal :functional-test:build
I suspect your problem is because of known classloader issues with plugins exercised with Gradle's TestKit.
I will paraphrase what that link says: Your plugin and its runtime classpath are loaded with one classloader. The functional test and its classpath are loaded in yet a second different classloader. Such a situation is the classic recipe for NoClassDefFoundErrors. Therefore, when using TestKit with a custom plugin, the plugin's runtime classpath must be explicitly injected into the runtime classpath of the functional test that is exercising the plugin.
The way your project is organized — with the functional test as a subproject — is likely to compound those known classloader issues. It certainly makes things more complicated than they need to be.
The answer to your question, therefore, is: Reorganize your project.
Using the Gradle User Guide as a guide, I simplified your project.
I forked and reorganized it the way Gradle advises.
The fixed code is in the able-to-add-dependencies branch of the fork.

JDK 11 + JUnit 5 + Jigsaw: Junit fails to run tests for `module-info`

I try to use JUnit 5 in a Gradle project. compileJava and compileTestJava both succeed, but test fails with the strange message Could not execute test class 'module-info'. (message from stacktrace):
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/axel/git/utility/build/reports/tests/test/index.html
The test result file hints me that "failed to execute tests", but the stack trace looks weird. It seems JUnit is trying to run the class corresponding to my module-info.java file:
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not execute test class 'module-info'.
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:53)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:117)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: module-info is not a class because access_flag ACC_MODULE is set
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:801)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.loadClass(JUnitPlatformTestClassProcessor.java:103)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.access$200(JUnitPlatformTestClassProcessor.java:54)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.execute(JUnitPlatformTestClassProcessor.java:82)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.execute(JUnitPlatformTestClassProcessor.java:77)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
... 25 more
versions used:
jin:utility axel$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
jin:utility axel$ ./gradlew -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/axel/.gradle/wrapper/dists/gradle-4.10.2-bin/cghg6c4gf4vkiutgsab8yrnwv/gradle-4.10.2/lib/groovy-all-2.4.15.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------
Build time: 2018-09-19 18:10:15 UTC
Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 11 (Oracle Corporation 11+28)
OS: Mac OS X 10.14 x86_64
jin:utility axel$ grep -i junit build.gradle
// JUnit
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
useJUnitPlatform()
Does anyone know how to tell JUnit not to try to run module-info or any other workaround?
Ignoring module-info.class at test-runtime is "Resort to the class-path": https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world#resort-to-the-classpath -- your tests may access internal classes as before. All modular boundaries are discarded.
If you want stay in the modular world when doing white box tests, you need to patch your main and test modules into a single one. Either at test compile or test runtime. More information about that test modes can also be found in the blog linked above.
For a Gradle setup you may either use the JUnit ConsoleLauncher manually or re-configure the Gradle runtime paths like described here https://guides.gradle.org/building-java-9-modules/ and/or use https://github.com/zyxist/chainsaw
Works if I add a filter in build.gradle:
test {
useJUnitPlatform()
filter {
exclude '**/module-info.class'
}
}

Spring Throws NoSuchMethodError Exception

When I'm trying to run the below code
#Override
public List<EventDetails> process(int event_status) throws EventDetailDataException {
String sql="select * from MicroServiceEventDetails where event_status=?";
List<EventDetails> EventDetailsList = template.query(sql, new BeanPropertyRowMapper<EventDetails>(EventDetails.class),new Object[] {event_status});
return EventDetailsList;
}
It throws the following exception and here's the error log:-
Apr 02, 2017 6:26:04 AM org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler handleError
SEVERE: Unexpected error occurred in scheduled task.
java.lang.NoSuchMethodError: org.springframework.core.convert.support.DefaultConversionService.getSharedInstance()Lorg/springframework/core/convert/ConversionService;
at org.springframework.jdbc.core.BeanPropertyRowMapper.<init>(BeanPropertyRowMapper.java:91)
at com.syntel.boot.dao.EventProcessDaoImpl.process(EventProcessDaoImpl.java:38)
at com.syntel.boot.services.EventDetailServiceImpl.process(EventDetailServiceImpl.java:73)
at com.syntel.boot.scheduler.microeventschudler.eventExcuter(microeventschudler.java:30)
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.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Maybe maven dependencies would be the reason i'm not sure, help?
I assume you are using Maven/Gradle, any build tool.
I was working on a spring MVC project and added LDAP functionality, however I added the LDAP jar dependency on the top of the dependency list in pom.xml and the jar version I used, utilized a lower version of spring core which did not have the ConversionService class. I identified this by back tracking to what was the most recent change to the Spring jar versions I made(i.e. added ldap libs) and using the Maven - Dependency hierarchy tab to identify what had changed. Once I removed the new dependency. did a clean, install, add the dependencies to the bottom of the list. The issue was fixed.
Your resolved dependencies should have the highest spring core version referenced on the column on the left. Any lower version should be omitted. In the screenshot, notice that spring core 4.3.9 is omitted for 4.3.4. Avoid this by adding the dependencies that use lower spring core versions below those which use higher versions.

Resources