java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException - java

I want to add end to end tests to my sprint boot application and I follow along this tutorial: https://reflectoring.io/spring-boot-web-controller-test/
package com.example.petstore.backend.api.implementation;
import com.example.petstore.backend.api.model.Pet;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
#ExtendWith(SpringExtension.class)
#WebMvcTest(controllers = PetController.class)
public class PetControllerE2E {
#Autowired
private MockMvc mockMvc;
#Autowired
private ObjectMapper objectMapper;
#Test
void whenValidInput_thenReturns200() throws Exception {
Pet pet = new Pet().id(0L);
mockMvc.perform(post("/pet")
.contentType("application/json")
.content(objectMapper.writeValueAsString(pet)))
.andExpect(status().isOk());
}
}
Now If I run this test I get:
org/junit/jupiter/api/extension/ScriptEvaluationException
java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ScriptEvaluationException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at org.junit.jupiter.engine.extension.ScriptExecutionCondition$Evaluator.forName(ScriptExecutionCondition.java:153)
at org.junit.jupiter.engine.extension.ScriptExecutionCondition$Evaluator.forName(ScriptExecutionCondition.java:133)
at org.junit.jupiter.engine.extension.ScriptExecutionCondition.<init>(ScriptExecutionCondition.java:55)
at org.junit.jupiter.engine.extension.ScriptExecutionCondition.<init>(ScriptExecutionCondition.java:50)
at org.junit.jupiter.engine.extension.ExtensionRegistry.<clinit>(ExtensionRegistry.java:54)
at org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.prepare(JupiterEngineDescriptor.java:37)
at org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.prepare(JupiterEngineDescriptor.java:28)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:75)
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:229)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
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:61)
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: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 com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
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:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
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:56)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.junit.jupiter.api.extension.ScriptEvaluationException
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:522)
... 50 more
UnknownClass > initializationError FAILED
java.lang.NoClassDefFoundError at Class.java:-2
Caused by: java.lang.ClassNotFoundException at BuiltinClassLoader.java:581
1 test completed, 1 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
My gradle file is:
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id "org.openapi.generator" version "5.0.0-beta2"
id "io.freefair.lombok" version "5.2.1"
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'//crudrepo
implementation 'org.springframework.security:spring-security-crypto'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
/* required per tutorial */
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testCompile 'org.mockito:mockito-junit-jupiter:2.23.0'
/* added from other questions */
testCompile 'org.junit.platform:junit-platform-launcher:1.4.0'
testCompile 'org.junit.jupiter:junit-jupiter:5.4.0'
testCompile group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.7.1'
}
test {
useJUnitPlatform()
}
...
So it would seem org/junit/jupiter/api/extension/ScriptEvaluationException is missing because I forgot a dependency.
However that class should be part of https://junit.org/junit5/docs/5.4.0/api/org/junit/jupiter/api/extension/ScriptEvaluationException.html and thus contained in
testCompile 'org.junit.jupiter:junit-jupiter:5.4.0'.
Why do get this error? How can I fix this?

using
testCompile 'org.junit.jupiter:junit-jupiter:5.4.0'
works.

Related

Spring boot application works with IntelliJ, however fails with NoSuchMethodError while running with gradle bootRun

My spring boot application works perfectly while executed from IntelliJ Idea, however when I try to run it with bootRun it complies, but throws NoSuchMethodError while executing.
build.gradle file is listed below.
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = "16"
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.github.salesforce-marketingcloud:fuelsdk:1.6.0'
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.2'
compileOnly 'org.projectlombok:lombok:1.18.24'
developmentOnly 'org.springframework.boot:spring-boot-devtools:2.7.2'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor:2.7.2'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.2'
}
tasks.named('test') {
useJUnitPlatform()
}
targetCompatibility = JavaVersion.VERSION_16
Also the stacktrace of the error:
java.lang.NoSuchMethodError: 'org.codehaus.stax2.ri.EmptyIterator org.codehaus.stax2.ri.EmptyIterator.getInstance()'
at com.ctc.wstx.sw.OutputElementBase.getPrefixes(OutputElementBase.java:358) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at org.apache.cxf.staxutils.StaxUtils.writeStartElement(StaxUtils.java:789) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.staxutils.StaxUtils.copy(StaxUtils.java:737) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.staxutils.StaxUtils.copy(StaxUtils.java:701) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.staxutils.StaxUtils.copy(StaxUtils.java:625) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.interceptor.AbstractLoggingInterceptor.writePayload(AbstractLoggingInterceptor.java:168) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback.onClose(LoggingOutInterceptor.java:249) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:209) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:652) ~[cxf-rt-transports-http-3.1.2.jar:3.1.2]
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277) ~[cxf-core-3.1.2.jar:3.1.2]
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) ~[cxf-rt-frontend-simple-3.1.2.jar:3.1.2]
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139) ~[cxf-rt-frontend-jaxws-3.1.2.jar:3.1.2]
at jdk.proxy3/jdk.proxy3.$Proxy88.retrieve(Unknown Source) ~[na:na]
at com.exacttarget.fuelsdk.ETSoapObject.retrieve(ETSoapObject.java:350) ~[fuelsdk-1.6.0.jar:na]
at com.exacttarget.fuelsdk.ETSoapObject.retrieve(ETSoapObject.java:173) ~[fuelsdk-1.6.0.jar:na]
at com.exacttarget.fuelsdk.ETSoapObject.retrieve(ETSoapObject.java:149) ~[fuelsdk-1.6.0.jar:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at com.exacttarget.fuelsdk.ETClient.retrieve(ETClient.java:630) ~[fuelsdk-1.6.0.jar:na]
at com.exacttarget.fuelsdk.ETClient.retrieve(ETClient.java:569) ~[fuelsdk-1.6.0.jar:na]
at com.example.sfmcbackend.service.DERetrievalService.getDataExtensionByName(DERetrievalService.java:18) ~[main/:na]
I've checked the classpath both runtime and compile and all of the dependecies are there, as well as the dependency which is causing the error.
The method which causes the error is this
https://javadoc.io/doc/org.codehaus.woodstox/stax2-api/latest/index.html
Check the documentation for the version you're using, maybe there is no getInstance method in that version.
I don't see any reference to that dependency in your gradle file, it is probably imported by one of your dependencies. I'm not an expert with gradle, but you can try the gradle equivalent for mvn tree to get all the infos.
If you find out that the version does not have getInstance method, you can import it manually with excluding the version imported by your dependency.
Once again this a solution i used with maven, but i assume gradle offers similar functionnalities.

java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils in SOAP web service test

I have generated SOAP web service in spring boot and the endpoint works fine.
Then I added some test for that endpoint and I get the following error stack while running the test:
21:33:51.263 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [ms.template.XohksMxControllerTest]: class path resource [ms/template/XohksMxControllerTest-context.xml] does not exist
21:33:51.264 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [ms.template.XohksMxControllerTest]: class path resource [ms/template/XohksMxControllerTestContext.groovy] does not exist
21:33:51.264 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [ms.template.XohksMxControllerTest]: no resource found for suffixes {-context.xml, Context.groovy}.
java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils
at org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory.createContextCustomizer(OverrideAutoConfigurationContextCustomizerFactory.java:41)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.getContextCustomizers(AbstractTestContextBootstrapper.java:404)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:376)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:294)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:101)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:137)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.TestContextAnnotationUtils
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)
... 26 more
Process finished with exit code -1
** The dependencies that I use are the following:**
plugins {
id 'org.springframework.boot' version "2.3.4.RELEASE"
id 'io.spring.dependency-management' version "1.0.10.RELEASE"
id 'java'
id 'jacoco'
id 'checkstyle'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation "junit:junit:4.13
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
implementation "org.glassfish.jaxb:jaxb-runtime:4.0.0"
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
implementation group: 'javax.activation', name: 'activation', version: '1.1.1'
implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
implementation group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'
jaxb "org.glassfish.jaxb:jaxb-xjc:4.0.0"
jaxb "org.glassfish.jaxb:jaxb-runtime:4.0.0"
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: "2.0.7"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-test-autoconfigure', version: '2.6.5'
testImplementation group: 'org.springframework.ws', name: 'spring-ws-test', version: '3.1.2'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.3.4.RELEASE'
}
The java code that I use for the test is the following:
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.ws.test.server.RequestCreator;
import org.springframework.ws.test.server.RequestCreators;
import org.springframework.ws.test.server.ResponseMatcher;
import org.springframework.ws.test.server.ResponseMatchers;
#RunWith(SpringRunner.class)
#SpringBootTest(classes = TemplateApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#ContextConfiguration(classes = XohksMxControllerTest.class)
public class XohksMxControllerTest {
#Autowired
ApplicationContext applicationContext;
private MockWebServiceClient client;
#Autowired
private ResourceLoader resourceLoader;
#Before
public void createClient() {
Assertions.assertNotNull(applicationContext);
client = MockWebServiceClient.createClient(applicationContext);
}
#Test
public void mockServerCall() throws IOException {
final RequestCreator requestCreator;
final ResponseMatcher responseMatcher;
client = MockWebServiceClient.createClient(applicationContext);
Resource requestPayLoad = resourceLoader.getResource("requestPayload.xml");
Resource responsePayload = resourceLoader.getResource("responsePayload.xml");
requestCreator = RequestCreators
.withSoapEnvelope(requestPayLoad);
responseMatcher = ResponseMatchers.soapEnvelope(responsePayload);
client.sendRequest(requestCreator).andExpect(responseMatcher);
}
}
I tried to change the versions of spring-boot-starter-test dependency to make it same with the spring boot version (2.3.4.RELEASE), but it did not work.
Adding spring-test dependency solved the issue:
testImplementation group: 'org.springframework', name: 'spring-test', version: '5.3.8'

Why does my Gradle Build does not work with Lombok?

I'm currently programming a Spring Boot Application and I want to use Lombok to make things easier.
When I try to perform the gradle build, I get the error message:
Execution failed for task ':checkLombokConfig'.
> java.nio.charset.MalformedInputException: Input length = 1
The full error looks like this:
org.gradle.api.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:61)
at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:41)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:107)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:506)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
at ...
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)
at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:352)
at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188)
at java.base/java.io.InputStreamReader.read(InputStreamReader.java:178)
at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:329)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:396)
at java.base/java.nio.file.Files.readAllLines(Files.java:3399)
at java.base/java.nio.file.Files.readAllLines(Files.java:3436)
at io.freefair.gradle.plugins.lombok.tasks.CheckLombokConfig.check(CheckLombokConfig.java:50)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
...
Root cause: java.nio.charset.MalformedInputException: Input length = 1
at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)
at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:352)
at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188)
at java.base/java.io.InputStreamReader.read(InputStreamReader.java:178)
at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:329)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:396)
at java.base/java.nio.file.Files.readAllLines(Files.java:3399)
at java.base/java.nio.file.Files.readAllLines(Files.java:3436)
at io.freefair.gradle.plugins.lombok.tasks.CheckLombokConfig.check(CheckLombokConfig.java:50)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:506)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
...
My build file looks like this:
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'application'
id 'io.freefair.lombok' version '6.1.0-m3'
}
group = 'de.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
implementation 'org.webjars:bootstrap:4.6.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
}
test {
useJUnitPlatform()
}
// Make implicit dependency explicit
startScripts {
dependsOn(bootJar)
}
// Define the main class for the "gradle run" task
mainClassName = 'de.test.testApplication'
// Disable generation of zip and tar distributions.
tasks.distZip.enabled = false
tasks.distTar.enabled = false
tasks.bootDistZip.enabled = false
tasks.bootDistTar.enabled = false
I can only run the project as "Spring Boot App" when I add the annotation processor manually in my IDE.
I am using SpringToolsSuite4 and Java 11 on Windows.
Does somebody know how I can fix this problem? Thank you!
Try adding
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
in your build.gradle file

Spring Boot application run fails, even after rolling back to last successful build commit

This is my first question here, so please be kind...
I have a SpringBoot REST API running with gradle.
I recently added a new dependency in my build.gradle (implementation group: 'com.smsfactor', name: 'smsfactor', version: '1.0'), made some code, and when I tried to run the app, I had this error :
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi
Quite surprising because I didn't make any new use of the lombok library. First thing I did was adding a mapstruct dependency to my build.gradle. I also tried to define a version (1.18.20, same as on my Eclipse install) for my lombok dependency, which wasn't set before.
Both actions independently solved the issue, but created another one :
2021-04-29 12:36:51.104 ERROR 4971 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.configuration.ModelsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#21213b92]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.8.RELEASE.jar:na]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:100) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:na]
at com.feudjey.picsession.PicSessionApplication.main(PicSessionApplication.java:11) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at spring.boot.devtools#2.4.5/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:na]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466) ~[na:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.8.RELEASE.jar:na]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 30 common frames omitted
2021-04-29 12:36:51.120 WARN 4971 --- [ restartedMain] o.s.boot.SpringApplication : Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.schema.configuration.ModelsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#21213b92]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.8.RELEASE.jar:na]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:620) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.beans#5.2.8.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612) ~[spring-beans-5.2.8.RELEASE.jar:na]
at spring.context#5.2.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1243) ~[spring-context-5.2.8.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:880) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:868) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:855) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:806) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:325) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:na]
at spring.boot#2.3.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:na]
at com.feudjey.picsession.PicSessionApplication.main(PicSessionApplication.java:11) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at spring.boot.devtools#2.4.5/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:na]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466) ~[na:na]
at spring.core#5.2.8.RELEASE/org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.8.RELEASE.jar:na]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 30 common frames omitted
The thing is that I have "com.fasterxml:classmate:1.5.1" in my project when I run gradle dependencies. I found many threads about this dependency, but usualy users did not have included it in their project, which isn't my case.
The other weird thing is that when I stash my changes to go back to my last good build state, I encounter the same first error about lombok.
I started coding in java 4 years ago, I always find a solution to my issue in this community forums, but today I am totally lost, that's why I am writing my first thread.
Here is my build.gradle :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:'2.4.5'"
}
}
plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'eclipse'
id 'java'
id 'war'
}
bootWar {
archiveName 'rest-api.war'
}
group = 'com.feudjey'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
// Security
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.4.3'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
// Swagger
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
// File management
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation group: 'org.imgscalr', name: 'imgscalr-lib', version: '4.2'
implementation group: 'com.drewnoakes', name: 'metadata-extractor', version: '2.14.0'
// Validation
implementation group: 'org.hibernate', name: 'hibernate-validator-annotation-processor', version: '7.0.1.Final'
implementation group: 'org.hibernate.validator', name: 'hibernate-validator', version: '7.0.1.Final'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
implementation group: 'org.glassfish', name: 'javax.el', version: '3.0.0'
// Misc
implementation group: 'com.google.api-client', name: 'google-api-client', version: '1.30.10'
// Mapper
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.4.2'
// Faker
implementation group: 'com.github.javafaker', name: 'javafaker', version: '1.0.2'
// eMail
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.4.2'
// SMS
implementation group: 'com.smsfactor', name: 'smsfactor', version: '1.0'
// Paypal
implementation group: 'com.paypal.sdk', name: 'rest-api-sdk', version: '1.14.0'
// Persistance
implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
// Database
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: '42.2.20'
// Dev Tools
developmentOnly group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.4.5'
// Lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
// Tests
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
javac 11.0.10
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9)
OpenJDK 64-Bit Server VM (build 11.0.10+9, mixed mode)
Edit :
When I remove these two dependencies (and the code using them)
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'com.fasterxml.jackson.core:jackson-databind', version: '2.9.6'
I get get the following error :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repository in com.feudjey.picsession.services.ServiceBase required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Does this make any sense ?
Here is my configuration class :
package com.feudjey.picsession.configuration;
import java.time.OffsetDateTime;
import java.util.Optional;
import org.modelmapper.ModelMapper;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import com.feudjey.picsession.contracts.GlobalContract;
#Configuration
#EnableJpaAuditing(dateTimeProviderRef = "auditingDateTimeProvider")
#EnableJpaRepositories(basePackages = {GlobalContract.BASE_PACKAGE + ".repositories"})
#EntityScan(basePackages = {GlobalContract.BASE_PACKAGE + ".entities"})
#ComponentScan(basePackages = {
GlobalContract.BASE_PACKAGE + ".events",
GlobalContract.BASE_PACKAGE + ".services",
GlobalContract.BASE_PACKAGE + ".mappers",
GlobalContract.BASE_PACKAGE + ".fixtures"})
public class ApplicationConfig {
#Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
// #Bean
// public Docket api() {
// return new Docket(DocumentationType.SWAGGER_2)
// .select()
// .apis(RequestHandlerSelectors.basePackage(GlobalContract.BASE_PACKAGE + ".controllers"))
// .paths(PathSelectors.any())
// .build();
// }
#Bean
public DateTimeProvider auditingDateTimeProvider() {
return () -> Optional.of(OffsetDateTime.now());
}
#Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final String origin = "*";
final String header = "*";
final String method = "*";
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin(origin);
config.addAllowedHeader(header);
config.addAllowedMethod(method);
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
#Bean
public ApplicationEventMulticaster applicationEventMulticaster() {
final SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
return eventMulticaster;
}
}
Edit 2 :
OK, I've just noticed that the project runs perfectly whith gradle bootrun, but doesn't with eclipse, so I have no debug mode.
I do a gradle cleaneclipse eclipse before every eclipse build, so what can it be ?
Please ask me if you want more details about my project. Hope someone can help me.
Thanks.

io.cucumber.core.exception.CucumberException: Couldn't load plugin class: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter

I'm new on stackoverflow, I'm really in trouble and I need help! :)
I'm developing a test automation program in Java using jdk-11 with Cucumber + Extent Reports.
When I try to run my Runner class with JUnit, I got this error message:
io.cucumber.core.exception.CucumberException: Couldn't load plugin class: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter
at io.cucumber.core.options.PluginOption.loadClass(PluginOption.java:117)
at io.cucumber.core.options.PluginOption.parsePluginName(PluginOption.java:102)
at io.cucumber.core.options.PluginOption.parse(PluginOption.java:86)
at io.cucumber.core.options.RuntimeOptionsBuilder$ParsedPluginData.addPluginName(RuntimeOptionsBuilder.java:238)
at io.cucumber.core.options.RuntimeOptionsBuilder.addPluginName(RuntimeOptionsBuilder.java:62)
at io.cucumber.core.options.CucumberOptionsAnnotationParser.addPlugins(CucumberOptionsAnnotationParser.java:97)
at io.cucumber.core.options.CucumberOptionsAnnotationParser.parse(CucumberOptionsAnnotationParser.java:52)
at io.cucumber.junit.Cucumber.<init>(Cucumber.java:112)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder.buildRunner(DefensiveAllDefaultPossibilitiesBuilder.java:114)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder.runnerForClass(DefensiveAllDefaultPossibilitiesBuilder.java:57)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.vintage.engine.discovery.ClassSelectorResolver.resolveTestClass(ClassSelectorResolver.java:66)
at org.junit.vintage.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:47)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:134)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1631)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:185)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:125)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:91)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:82)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.vintage.engine.discovery.VintageDiscoverer.discover(VintageDiscoverer.java:44)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:63)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:168)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.NoClassDefFoundError: cucumber/api/event/ConcurrentEventListener
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:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
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)
at io.cucumber.core.options.PluginOption.loadClass(PluginOption.java:110)
... 44 more
Caused by: java.lang.ClassNotFoundException: cucumber.api.event.ConcurrentEventListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 54 more
So, in my Runner class, called "LoginPageSuite.class", I have:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
strict = true,
features = {"src/test/resources/features/login"},
glue = {"com/cologni/functional_testing_framework/step_definitions/login"},
// Reports
plugin = {"pretty",
"html:reports/cucumber-html-report",
"json:reports/cucumber-report.json",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:reports/extent-report.html"
}
)
public class LoginPageSuite {
}
And in my "build.gradle" file I have these dependencies:
plugins {
id 'java'
}
group 'com.cologni'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'com.cologni.functional_testing_framework.step_definitions', 'src/test/resources/features/']
}
}
}
dependencies {
// JUnit API
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
// JUnit Engine
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.0'
// Cucumber Java
compile group: 'io.cucumber', name: 'cucumber-java', version: '5.3.0'
// Cucumber Java 8
compile group: 'io.cucumber', name: 'cucumber-java8', version: '5.3.0'
// Cucumber JUnit
testCompile group: 'io.cucumber', name: 'cucumber-junit', version: '5.3.0'
//Cucumber Pico Container
testCompile group: 'io.cucumber', name: 'cucumber-picocontainer', version: '5.3.0'
// Selenium
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
// Cucumber 4 - Extent Reports
compile group: 'com.aventstack', name: 'extentreports-cucumber4-adapter', version: '1.0.10'
// JSON
compile group: 'org.json', name: 'json', version: '20190722'
}
test {
useJUnitPlatform()
}
I tried everything, I tried to import different dependencies like:
compile group: 'com.aventstack', name: 'extentreports', version: '4.1.3'
But I'm using the extent reports cucumber adapter
compile group: 'com.aventstack', name: 'extentreports-cucumber4-adapter', version: '1.0.10'
I really tried everything, I searched for everything, but I can't solve this, could anyone help me? I'll be glad. Thank you very much!
The answer is in your own dependencies:
compile group: 'io.cucumber', name: 'cucumber-java', version: '5.3.0'
// Cucumber 4 - Extent Reports
compile group: 'com.aventstack', name: 'extentreports-cucumber4-adapter', version: '1.0.10'

Categories