Skip to content

Spring Boot gradle plugin doesn't create a proper native image from a gradle subproject #45239

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

Open
boszormenyip opened this issue Apr 19, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@boszormenyip
Copy link

Case 1

Given the following gradle project structure.

Root project
Spring Boot gradle plugin is defined in the build.gradle.kts file, but it is not applied.

plugins {
    id("org.springframework.boot") version "3.4.4" apply false
}

cli subproject
The following plugins are applied:

plugins {
    java
    id("org.springframework.boot")
    id("org.graalvm.buildtools.native") version "0.10.6"
}

If I execute a ./gradlew cli:nativeRun command, I get this error from the running application:

org.springframework.boot.AotInitializerNotFoundException: Startup with AOT mode enabled failed: AOT initializer cli.CliMain__ApplicationContextInitializer could not be found
        at org.springframework.boot.SpringApplication.addAotGeneratedInitializerIfNecessary(SpringApplication.java:426)
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:382)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at cli.CliMain.main(CliMain.java:12)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

Case 2

Given the following gradle project structure

Root project
Spring Boot gradle plugin is defined in the build.gradle.kts file, but it is not applied. Also the GraalVM plugin is defined, but not applied. Note: The difference here is, that in case 1 the GraalVM plugin is not here.

plugins {
    id("org.springframework.boot") version "3.4.4" apply false
    id("org.graalvm.buildtools.native") version "0.10.6" apply false
}

cli subproject
The following plugins are applied.

plugins {
    java
    id("org.springframework.boot")
    id("org.graalvm.buildtools.native")
}

If I execute a ./gradlew cli:nativeRun command, the command runs without any problem.


It seems the problem is a class loading issue. The org.springframework.boot.gradle.plugin.SpringBootPlugin tries to load several other plugin classes. (Line: 149). In case 1, when the org.springframework.boot.gradle.plugin.NativeImagePluginAction.getPluginClass() is called, the method throws a NoClassDefFoundError, which will be caught, and the NativeImagePlugnAction will be skipped.
In case 2, the org.springframework.boot.gradle.plugin.NativeImagePluginAction.getPluginClass() doesn't throw a NoClassDefFoundError, soe the the NativeImagePluginAction can apply its things on the project.

The exceptation would be either the case 1 works, or the documentation mention that, that the GraalVM gradle plugin has to be loaded in root project.

The two cases are in the two zip files. The reproduction: execute the ./gradlew cli:nativeRun command. GraalVM has to be the active Java implementation. The native-image command of GraalVM needs some additional tools/libraries: Copied from https://www.graalvm.org/latest/reference-manual/native-image/: "header files for the C library, glibc-devel, zlib, gcc, and/or libstdc++-static".

Version information

Java

openjdk version "24.0.1" 2025-04-15
OpenJDK Runtime Environment GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01)
OpenJDK 64-Bit Server VM GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01, mixed mode, sharing)

Spring Boot plugin
3.4.4

case1.zip
case2.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 19, 2025
@quaff
Copy link
Contributor

quaff commented Apr 21, 2025

It may be duplicate of #43493.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants