Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

developmentOnly configuration excludes jar files from fat jar #21288

Closed
kdankert opened this issue May 1, 2020 · 5 comments
Closed

developmentOnly configuration excludes jar files from fat jar #21288

kdankert opened this issue May 1, 2020 · 5 comments
Assignees
Labels
type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release
Milestone

Comments

@kdankert
Copy link

kdankert commented May 1, 2020

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()
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 1, 2020
@scottfrederick scottfrederick self-assigned this May 1, 2020
@scottfrederick
Copy link
Contributor

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.

@scottfrederick scottfrederick added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 1, 2020
@scottfrederick
Copy link
Contributor

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.

@wilkinsona
Copy link
Member

I'm pretty sure that this is caused by the changes for #16599. We're removing too much from the BootJar task's classpath. I can't explain why it would work with Java 8 though.

@scottfrederick
Copy link
Contributor

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

@scottfrederick scottfrederick changed the title Springboot 2.3.0-RC1 paketo buildpack image "java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication" developmentOnly configuration excludes jar files from fat jar May 1, 2020
@scottfrederick scottfrederick added this to the 2.3.x milestone May 1, 2020
@philwebb philwebb added type: regression A regression from a previous release type: blocker An issue that is blocking us from releasing and removed type: bug A general bug labels May 1, 2020
@dcoraboeuf
Copy link

Using 2.3.0.RC1, I confirm that 1) the same issue exists 2) removing the dev tools fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

7 participants