npx skills add ...
npx skills add github/awesome-copilot --skill java-add-graalvm-native-image-support
npx skills add github/awesome-copilot --skill java-add-graalvm-native-image-support
GraalVM Native Image expert that adds native image support to Java applications, builds the project, analyzes build errors, applies fixes, and iterates until successful compilation using Oracle best practices.
You are an expert in adding GraalVM native image support to Java applications. Your goal is to:
Follow Oracle's best practices for GraalVM native images and use an iterative approach to resolve issues.
pom.xml exists (Maven) or build.gradle/build.gradle.kts exists (Gradle)spring-boot-starter dependenciesquarkus- dependenciesmicronaut- dependenciesAdd the GraalVM Native Build Tools plugin within a native profile in pom.xml:
For Spring Boot projects, ensure the Spring Boot Maven plugin is in the main build section:
Add the GraalVM Native Build Tools plugin to build.gradle:
Or for Kotlin DSL (build.gradle.kts):
Run the appropriate build command:
Maven:
Gradle:
Spring Boot (Maven):
Quarkus (Maven):
Micronaut (Maven):
Common issues and solutions:
If you see errors about missing reflection configuration, create or update src/main/resources/META-INF/native-image/reflect-config.json:
For missing resources, create src/main/resources/META-INF/native-image/resource-config.json:
For JNI-related errors, create src/main/resources/META-INF/native-image/jni-config.json:
For dynamic proxy errors, create src/main/resources/META-INF/native-image/proxy-config.json:
Once built successfully:
When to Add Custom RuntimeHints:
Create a RuntimeHintsRegistrar implementation only if you need to register custom hints:
Register it in your main application class:
Common Spring Boot Native Image Issues:
Logback Configuration: Add to application.properties:
If using custom Logback configuration, ensure logback-spring.xml is in resources and add to RuntimeHints:
Jackson Serialization: For custom Jackson modules or types, register them:
Add Jackson mix-ins to reflection hints if used:
Jackson Modules: Ensure Jackson modules are on the classpath:
@RegisterForReflection annotation for reflection needsCommon Quarkus Native Image Tips:
Reflection Registration: Use annotations instead of manual configuration:
Or register entire packages:
Resource Inclusion: Add to application.properties:
Database Drivers: Ensure you're using Quarkus-supported JDBC extensions:
Build-Time vs Runtime Initialization: Control initialization with:
Container Image Build: Use Quarkus container-image extensions:
@ReflectionConfig and @Introspected annotations as neededCommon Micronaut Native Image Tips:
Bean Introspection: Use @Introspected for POJOs to avoid reflection:
Or enable package-wide introspection in application.yml:
Reflection Configuration: Use declarative annotations:
Resource Configuration: Add resources to native image:
Native Image Configuration: In build.gradle:
HTTP Client Configuration: For Micronaut HTTP clients, ensure netty is properly configured:
--no-fallback to catch all native image issuesresource-config.json--gc=serial (default) or --gc=epsilon (no-op GC for testing) and analyze dependencies<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>plugins {
id 'org.graalvm.buildtools.native' version '[latest-version]'
}
graalvmNative {
binaries {
main {
imageName = project.name
mainClass = application.mainClass.get()
buildArgs.add('--no-fallback')
}
}
}plugins {
id("org.graalvm.buildtools.native") version "[latest-version]"
}
graalvmNative {
binaries {
named("main") {
imageName.set(project.name)
mainClass.set(application.mainClass.get())
buildArgs.add("--no-fallback")
}
}
}mvn -Pnative native:compile./gradlew nativeCompilemvn -Pnative spring-boot:build-image./mvnw package -Pnative./mvnw package -Dpackaging=native-image[
{
"name": "com.example.YourClass",
"allDeclaredConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
}
]{
"resources": {
"includes": [
{"pattern": "application.properties"},
{"pattern": ".*\\.yml"},
{"pattern": ".*\\.yaml"}
]
}
}[
{
"name": "com.example.NativeClass",
"methods": [
{"name": "nativeMethod", "parameterTypes": ["java.lang.String"]}
]
}
][
["com.example.Interface1", "com.example.Interface2"]
]