Spring Boot Native Image Compilation Fails in Docker with GraalVM: JNIHeaderDirectivesJDK21OrLater Error

167 Views Asked by At

I'm attempting to compile a native image of a Spring Boot application using GraalVM inside a Docker container, but I'm encountering a persistent error during the nativeBuild task. Below are the details of my environment and the error message.

Environment:

  • Spring Boot version: 3.2.1
  • GraalVM: VM GraalVM CE 21.0.1+12.1 (build 21.0.1+12, serial gc)
  • native-image: 21.0.1 2023-10-17
  • Docker Desktop: 4.26.1 (131620)
  • Build system: Gradle 8.5
  • Operating System: Windows 10 with WSL2 (running Docker Desktop)

Dockerfile:

FROM  ghcr.io/graalvm/native-image-community:21-muslib AS build
# Install to run gradlew
RUN microdnf install -y findutils
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
COPY src src
ENV SPRING_PROFILES_ACTIVE DEV
RUN chmod +x ./gradlew
RUN ./gradlew nativeBuild

Error Message:

> Task :nativeCompile
[native-image-plugin] GraalVM Toolchain detection is disabled
[native-image-plugin] GraalVM location read from environment variable: JAVA_HOME
[native-image-plugin] Native Image executable path: /usr/lib64/graalvm/graalvm-community-java21/lib/svm/bin/native-image
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/io.grpc.netty.shaded.io.netty/netty-transport/reflection-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-websocket/tomcat-reflection.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/tomcat-reflection.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/tomcat-resource.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-core/tomcat-reflection.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-el/tomcat-resource.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationResources=META-INF/native-image/org.apache.tomcat.embed/tomcat-embed-websocket/tomcat-resource.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: Please re-evaluate whether any experimental option is required, and either remove or unlock it. The build output lists all active experimental options, including where they come from and possible alternatives. If you think an experimental option should be considered as stable, please file an issue.
========================================================================================================================
GraalVM Native Image: Generating 'promptbuilder' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------

[1/8] Initializing...                                                                                    (0.0s @ 0.28GB)
------------------------------------------------------------------------------------------------------------------------
                        1.0s (15.2% of total time) in 32 GCs | Peak RSS: 1.14GB | CPU load: 5.92
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 /app/build/native/nativeCompile/svm_err_b_20240102T190459.122_pid884.md (build_info)
========================================================================================================================
Failed generating 'promptbuilder' after 5.7s.

The build process encountered an unexpected error:

> com.oracle.svm.core.util.VMError$HostedError: Unable to run '/tmp/SVM-11225349402971654161/JNIHeaderDirectivesJDK21OrLater' to compute offsets in C data structures. Is it possible that your antivirus software interferes and puts the resulting file into quarantine?

Please inspect the generated error report at:
/app/build/native/nativeCompile/svm_err_b_20240102T190459.122_pid884.md

If you are unable to resolve this problem, please file an issue with the error report at:

Has anyone encountered a similar issue or can provide insights on what might be going wrong and how to resolve it?

Any help or suggestions would be greatly appreciated!

0

There are 0 best solutions below