The docker image that is built with the default buildpack (paketo) in Springboot version 2.3.0-RC1 throws an error because the dependencies inside the container cannot be found. In 2.3.0-M4 this wasn't the case with the cloudfoundry buildpack.
Log of the docker container
Container memory limit unset. Configuring JVM for 1G container.
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=111994K -XX:ReservedCodeCacheSize=240M -Xss1M -Xmx424581K (Head Room: 0%, Loaded Class Count: 17359, Thread Count: 250, Total Memory: 1073741824)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.xerocs.comicro.chatservice.ChatServiceApplication.main(ChatServiceApplication.java:10)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:113)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more
Gradle Project File
plugins {
id 'org.springframework.boot' version '2.3.0.RC1'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = <groupId>
version = 'latest'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
bootBuildImage {
imageName = <imageName>
}
dependencies {
implementation platform("org.keycloak.bom:keycloak-adapter-bom:10.0.0")
implementation "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.2.6.RELEASE"
implementation "com.c4-soft.springaddons:spring-security-oauth2-test-webmvc-addons:2.0.3"
implementation 'org.keycloak:keycloak-spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
Comment From: scottfrederick
I can re-create this locally with a trivial app. The image runs with sourceCompatibility = '1.8'
but fails with sourceCompatibility = '11'
.
I get the same failure when building the image using pack build build-demo --builder gcr.io/paketo-buildpacks/builder:base-platform-api-0.3
, so the problem appears to be in the builder or a buildpack.
Comment From: scottfrederick
On further testing, it appears the failure only happens when DevTools is included with developmentOnly 'org.springframework.boot:spring-boot-devtools'
. Without that configuration, the image runs with Java 1.8 and Java 11.
Comment From: wilkinsona
I'm pretty sure that this is caused by the changes for https://github.com/spring-projects/spring-boot/issues/16599. We're removing too much from the BootJar
task's classpath. I can't explain why it would work with Java 8 though.
Comment From: scottfrederick
I've confirmed that this has nothing to do with the builder or buildpacks. If you include the developmentOnly
configuration and run the generated fat jar with java -jar
, you get the same startup failure.
Including the developmentOnly
configuration causes several jars to be excluded from the generated fat jar, including:
BOOT-INF/lib/spring-boot-autoconfigure-2.3.0.RC1.jar
BOOT-INF/lib/spring-boot-2.3.0.RC1.jar
BOOT-INF/lib/spring-context-5.2.6.RELEASE.jar
BOOT-INF/lib/spring-aop-5.2.6.RELEASE.jar
BOOT-INF/lib/spring-beans-5.2.6.RELEASE.jar
BOOT-INF/lib/spring-expression-5.2.6.RELEASE.jar
BOOT-INF/lib/spring-core-5.2.6.RELEASE.jar
BOOT-INF/lib/spring-jcl-5.2.6.RELEASE.jar
Comment From: dcoraboeuf
Using 2.3.0.RC1, I confirm that 1) the same issue exists 2) removing the dev tools fixes the issue