Java add graalvm native image support

From github/awesome-copilot · View interactive version

Java add graalvm native image support is an AI agent skill from the GitHub repository github/awesome-copilot. GraalVM Native Image skill for Spring Boot, Micronaut and plain Java: detects the build tool and framework, adds native image support, builds the executable, analyzes errors, and iterates until the native build succeeds and the binary runs correctly. For Quarkus projects it only dispatches to the qu

How to use this skill

Skill file

GraalVM Native Image Support

Single source of truth for adding GraalVM Native Image to a Java project, whatever the framework. Work iteratively: configure, build, read the error, fix, rebuild, until the native build succeeds and the executable runs correctly.

Detail lives in references/; load only what the project needs:

| Topic | File |

|---|---|

| Maven / Gradle native plugin setup | references/build-tools.md |

| Reachability metadata and tracing agent | references/reachability-metadata.md |

| Common build/runtime errors and fixes | references/troubleshooting.md |

| Spring Boot (AOT, -Pnative, nativeCompile, build-image) | references/spring-boot.md |

| Quarkus | quarkus-native-and-container skill (hand off); short pointer in references/quarkus.md |

| Micronaut | references/micronaut.md |

Step 1: Analyze the project

  1. Build tool: pom.xml (Maven) or build.gradle / build.gradle.kts (Gradle). Prefer the wrapper (./mvnw, ./gradlew) when present.
  2. Framework, from dependencies/plugins:
  1. Existing native configuration: native-build-tools plugin, META-INF/native-image/, native profile, application.properties native keys.
  2. Toolchain: run java -version and native-image --version. Local native compilation needs a GraalVM JDK (with native-image) as the JDK used for the build. Container or buildpack builds (Spring Boot buildpacks via bootBuildImage/spring-boot:build-image, Quarkus container builds) compile inside a container and need no local GraalVM, only a container runtime. Check the project's Java level against the installed GraalVM version.

If the framework is Quarkus, stop here and hand off to the quarkus-native-and-container skill. Container builds there need no local GraalVM.

Scope and JVM baseline

Step 2: Get a GraalVM toolchain

Step 3: Add native support

Per framework:

Step 4: Build

| Setup | Command |

|---|---|

| Plain Maven | ./mvnw -Pnative native:compile |

| Plain Gradle | ./gradlew nativeCompile |

| Spring Boot Maven | ./mvnw -Pnative native:compile (or spring-boot:build-image for a container) |

| Spring Boot Gradle | ./gradlew nativeCompile (or bootBuildImage) |

| Micronaut Maven | ./mvnw package -Dpackaging=native-image |

| Micronaut Gradle | ./gradlew nativeCompile |

Native builds are slow and memory hungry (several GB of RAM). Capture the full output to inspect it.

Step 5: Iterate until the build succeeds

  1. Read the first real error, not the final summary.
  2. Match it against references/troubleshooting.md.
  3. Apply the smallest fix, in this order of preference:

1. Check whether a compatible library/framework version has built-in native support (see the reachability metadata repository). Propose the upgrade; apply it only with user approval and rerun the JVM baseline. If declined, try metadata or framework hints compatible with the current versions.

2. Use the framework's own mechanism (Spring RuntimeHints, Quarkus @RegisterForReflection, Micronaut @Introspected).

3. Collect metadata with the tracing agent (see references/reachability-metadata.md).

4. Hand-write metadata under src/main/resources/META-INF/native-image/<groupId>/<artifactId>/.

5. Adjust initialization (--initialize-at-build-time / --initialize-at-run-time) only for specific classes.

  1. Rebuild. Repeat until the build completes with no errors.

Step 6: Verify the executable

A successful build is not enough: many problems only appear at runtime.

Pitfalls

References

Upstream sources (read before upgrading GraalVM or native config)

Fetch the page for the target version; prefer it over this skill when they conflict.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.