dependencies mismatch while upgrading spring version.
I am upgrading my service with spring boot 3.1.4.
This is my build.gradle.
plugins {
id 'org.springframework.boot' version '3.1.4'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
id 'eclipse'
id "com.diffplug.eclipse.apt" version "3.38.0"
id 'jacoco'
id 'org.sonarqube' version '3.3'
}
group = 'com.app.company'
version = '1.1.0'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-websocket'
//exclude group: 'commons-logging', module: 'commons-logging'
testImplementation.exclude group: 'org.projectlombok', module: 'lombok'
if (project.hasProperty('runTests')) {
testImplementation.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'jakarta.servlet') {
// to support jetty on spring boot 3.1.4
details.useVersion '6.0.0'
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
/* my configurations */
testImplementation 'junit:junit:4.13.1'
testImplementation'jakarta.servlet:jakarta.servlet-api:6.0.0'
testImplementation 'com.h2database:h2:1.4.200'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.mockito:mockito-core:3.12.4'
}
test {
useJUnitPlatform()
}
tasks.withType(JavaCompile) {
configure(options) {
options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
}
}
jacoco {
toolVersion = "0.8.10"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.required = true
// html.destination file("${rootProject.projectDir}/build/reports/jacoco")
xml.destination file("${rootProject.projectDir}/build/reports/jacoco/report.xml")
}
}
eclipse {
jdt {
apt {
// You need to run gradle eclipseJdtApt eclipseJdt eclipseFactorypath
// and restart vscode for this to take effect.
genSrcDir = file('build/generated/sources/annotationProcessor/java/main')
}
}
}
Here when I am using details.useVersion '5.0.0' my application is running but my testcase are fail to load with this error
java.lang.NoClassDefFoundError: jakarta/servlet/ServletConnection
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:210)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:130)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:241)
at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
...
Now when I am running details.useVersion '6.0.0' my testcase are running but application is not running, error I am getting
org.springframework.context.ApplicationContextException: Unable to start web server
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:602)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at com.app.company.CompanyApplication.main(CompanyApplication.java:22)
Caused by: java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpSessionContext
at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:339)
at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:432)
at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:257)
at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:180)
at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:301)
at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:228)
at org.springframework.boot.web.embedded.jetty.JettyEmbeddedWebAppContext.<init>(JettyEmbeddedWebAppContext.java:28)
at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:159)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161)
... 6 more
Caused by: java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext
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)
I was browising this page https://github.com/spring-projects/spring-boot/issues/33661 and for spring 3.1.4 we required 6.0.0. But using this my app run is failing.
what I supose to do or what I am missing here. Is there conditional check required.