• Setup
plugins {
    id("org.springframework.boot") version "3.0.0-RC1"
    id("io.spring.dependency-management") version "1.1.0"
    id("org.graalvm.buildtools.native") version "0.9.16"
    id("com.github.ben-manes.versions") version "0.43.0"
    kotlin("jvm") version "1.7.20"
    kotlin("plugin.spring") version "1.7.20"
}
dependencies {
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}
JDK:   java --version                                        
openjdk 19 2022-09-20
OpenJDK Runtime Environment GraalVM CE 23.0.0-dev (build 19+36-jvmci-23.0-b01)
OpenJDK 64-Bit Server VM GraalVM CE 23.0.0-dev (build 19+36-jvmci-23.0-b01, mixed mode, sharing)

Native image is created successfully but fails to start with the following exception. Have checked the documentation and didn't see anything mentioned about dev tools.

Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.boot.devtools.restart.RestartScopeInitializer] for factory type [org.springframework.context.ApplicationContextInitializer]
        at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:650)
        at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:674)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
        at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
        at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:459)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:455)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:273)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:252)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
        at dev.xxx.springnative.SpringNativeApplicationKt.main(SpringNativeApplication.kt:13)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.devtools.restart.RestartScopeInitializer
        at java.base@19/java.lang.Class.forName(DynamicHub.java:1138)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:283)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:224)
        ... 9 more

  • Native Image compilation log ```> 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: /Users/xxxx/install/graalvm/graalvm-ce-java19-23.0.0-dev/Contents/Home/lib/svm/bin/native-image ======================================================================================================================== GraalVM Native Image: Generating 'spring-native' (executable)... ======================================================================================================================== [1/7] Initializing... (14.4s @ 0.28GB) Version info: 'GraalVM 23.0.0-dev Java 19 CE' Java version info: '19+36-jvmci-23.0-b01' C compiler: cc (apple, arm64, 14.0.0) Garbage collector: Serial GC 1 user-specific feature(s)
  • org.springframework.aot.nativex.feature.PreComputeFieldFeature Field org.springframework.core.NativeDetector#imageCode set to true at build time Field org.springframework.core.KotlinDetector#kotlinPresent set to true at build time Field org.springframework.core.KotlinDetector#kotlinReflectPresent set to true at build time Field org.springframework.format.support.DefaultFormattingConversionService#jsr354Present set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#romePresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jaxb2Present set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jackson2Present set to true at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jackson2XmlPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jackson2SmilePresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jackson2CborPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#gsonPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#jsonbPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#kotlinSerializationCborPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#kotlinSerializationJsonPresent set to false at build time Field org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#kotlinSerializationProtobufPresent set to false at build time Field org.springframework.boot.logging.log4j2.Log4J2LoggingSystem$Factory#PRESENT set to false at build time Field org.springframework.boot.logging.java.JavaLoggingSystem$Factory#PRESENT set to true at build time Field org.springframework.boot.logging.logback.LogbackLoggingSystem$Factory#PRESENT set to true at build time Field org.springframework.web.servlet.view.InternalResourceViewResolver#jstlPresent set to false at build time Field org.springframework.web.context.support.StandardServletEnvironment#jndiPresent set to true at build time Field org.springframework.web.context.support.WebApplicationContextUtils#jsfPresent set to false at build time Field org.springframework.web.context.request.RequestContextHolder#jsfPresent set to false at build time Field org.springframework.context.event.ApplicationListenerMethodAdapter#reactiveStreamsPresent set to false at build time Field org.springframework.boot.autoconfigure.web.format.WebConversionService#JSR_354_PRESENT set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#jaxb2Present set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#jackson2Present set to true at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#jackson2XmlPresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#jackson2SmilePresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#gsonPresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#jsonbPresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#kotlinSerializationCborPresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#kotlinSerializationJsonPresent set to false at build time Field org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter#kotlinSerializationProtobufPresent set to false at build time Field org.springframework.core.ReactiveAdapterRegistry#reactorPresent set to false at build time Field org.springframework.core.ReactiveAdapterRegistry#rxjava3Present set to false at build time Field org.springframework.core.ReactiveAdapterRegistry#kotlinCoroutinesPresent set to false at build time Field org.springframework.core.ReactiveAdapterRegistry#mutinyPresent set to false at build time Field org.springframework.web.client.RestTemplate#romePresent set to false at build time Field org.springframework.web.client.RestTemplate#jaxb2Present set to false at build time Field org.springframework.web.client.RestTemplate#jackson2Present set to true at build time Field org.springframework.web.client.RestTemplate#jackson2XmlPresent set to false at build time Field org.springframework.web.client.RestTemplate#jackson2SmilePresent set to false at build time Field org.springframework.web.client.RestTemplate#jackson2CborPresent set to false at build time Field org.springframework.web.client.RestTemplate#gsonPresent set to false at build time Field org.springframework.web.client.RestTemplate#jsonbPresent set to false at build time Field org.springframework.web.client.RestTemplate#kotlinSerializationCborPresent set to false at build time Field org.springframework.web.client.RestTemplate#kotlinSerializationJsonPresent set to false at build time Field org.springframework.web.client.RestTemplate#kotlinSerializationProtobufPresent set to false at build time Processing of field org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler#isContextPropagationPresent skipped due the following error : org.slf4j.spi.SLF4JServiceProvider: ch.qos.logback.classic.spi.LogbackServiceProvider not a subtype Field org.springframework.boot.actuate.endpoint.web.annotation.DiscoveredWebOperation#REACTIVE_STREAMS_PRESENT set to false at build time Field org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker#IS_REACTOR_PRESENT set to false at build time Field org.springframework.boot.actuate.endpoint.invoke.reflect.OperationMethodParameter#jsr305Present set to false at build time Field org.springframework.web.servlet.support.RequestContext#jstlPresent set to false at build time [2/7] Performing analysis... [*] (31.4s @ 2.17GB) 19,409 (93.29%) of 20,804 classes reachable 30,930 (69.43%) of 44,548 fields reachable 92,182 (62.72%) of 146,970 methods reachable 900 classes, 186 fields, and 4,423 methods registered for reflection 62 classes, 63 fields, and 55 methods registered for JNI access 5 native libraries: -framework CoreServices, -framework Foundation, dl, pthread, z [3/7] Building universe... (4.5s @ 1.86GB) [4/7] Parsing methods... [*] (2.7s @ 3.88GB) [5/7] Inlining methods... [] (1.2s @ 3.09GB) [6/7] Compiling methods... [***] (14.2s @ 5.16GB) [7/7] Creating image... (10.8s @ 2.19GB) 40.51MB (48.57%) for code area: 59,826 compilation units 41.92MB (50.27%) for image heap: 420,815 objects and 333 resources 989.42KB ( 1.16%) for other data 83.39MB in total

Top 10 packages in code area: Top 10 object types in image heap: 1.70MB sun.security.ssl 9.62MB byte[] for code metadata 1.14MB java.util 4.76MB java.lang.Class 861.22KB java.lang.invoke 4.56MB byte[] for embedded resources 719.13KB com.sun.crypto.provider 4.14MB java.lang.String 641.71KB org.apache.tomcat.util.net 3.99MB byte[] for java.lang.String 618.96KB kotlin.reflect.jvm.internal.impl.metadata 3.25MB byte[] for general heap data 547.02KB org.apache.catalina.core 1.63MB com.oracle.svm.core.hub.DynamicHubCompanion 504.85KB java.lang 1.10MB byte[] for reflection metadata 487.28KB java.util.concurrent 826.16KB java.lang.String[] 476.73KB sun.security.x509 682.73KB c.o.svm.core.hub.DynamicHub$ReflectionMetadata 32.58MB for 793 more packages 6.31MB for 3812 more object types


                    4.2s (4.8% of total time) in 45 GCs | Peak RSS: 6.49GB | CPU load: 4.42

Produced artifacts: /Users/xxxx/code/spring-native/build/native/nativeCompile/spring-native (executable) /Users/xxxx/code/spring-native/build/native/nativeCompile/spring-native.build_artifacts.txt (txt) ======================================================================================================================== Finished generating 'spring-native' in 1m 27s. [native-image-plugin] Native Image written to: /Users/xxxx/code/spring-native/build/native/nativeCompile

BUILD SUCCESSFUL in 1m 51s ```