Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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.
.claude/skills/java-add-graalvm-native-image-support/SKILL.md| Model | Eval pass | Runs |
|---|---|---|
| gemini-3.6-flash | 95% | 66 |
| gemini-3.1-pro-previewlowest | 50% | 2 |
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-18 | ✗→✓ | ▲ Improved | — | — |
| case-16 | ✗→✓ | ▲ Improved | — | — |
| case-10 | ✗→✓ | ▲ Improved | — | — |
| case-05 | ✗→✓ | ▲ Improved | — | — |
| case-09 | ✗→✓ | ▲ Improved | — | — |
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:
xml<profiles> <profile> <id>native</id> <build> <plugins> <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <version>[latest-version]</version> <extensions>true</extensions> <executions> <execution> <id>build-native</id> <goals> <goal>compile-no-fork</goal> </goals> <phase>package</phase> </execution> </executions> <configuration> <imageName>${project.artifactId}</imageName> <mainClass>${main.class}</mainClass> <buildArgs> <buildArg>--no-fallback</buildArg> </buildArgs> </configuration> </plugin> </plugins> </build> </profile> </profiles>
For Spring Boot projects, ensure the Spring Boot Maven plugin is in the main build section:
xml<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
Add the GraalVM Native Build Tools plugin to build.gradle:
groovyplugins { id 'org.graalvm.buildtools.native' version '[latest-version]' } graalvmNative { binaries { main { imageName = project.name mainClass = application.mainClass.get() buildArgs.add('--no-fallback') } } }
Or for Kotlin DSL (build.gradle.kts):
kotlinplugins { 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") } } }
Run the appropriate build command:
Maven:
shmvn -Pnative native:compile
Gradle:
sh./gradlew nativeCompile
Spring Boot (Maven):
shmvn -Pnative spring-boot:build-image
Quarkus (Maven):
sh./mvnw package -Pnative
Micronaut (Maven):
sh./mvnw package -Dpackaging=native-image
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:
json[ { "name": "com.example.YourClass", "allDeclaredConstructors": true, "allDeclaredMethods": true, "allDeclaredFields": true } ]
For missing resources, create src/main/resources/META-INF/native-image/resource-config.json:
json{ "resources": { "includes": [ {"pattern": "application.properties"}, {"pattern": ".*\\.yml"}, {"pattern": ".*\\.yaml"} ] } }
For JNI-related errors, create src/main/resources/META-INF/native-image/jni-config.json:
json[ { "name": "com.example.NativeClass", "methods": [ {"name": "nativeMethod", "parameterTypes": ["java.lang.String"]} ] } ]
For dynamic proxy errors, create src/main/resources/META-INF/native-image/proxy-config.json:
json[ ["com.example.Interface1", "com.example.Interface2"] ]
sh java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar target/app.jar
Once built successfully:
When to Add Custom RuntimeHints:
Create a RuntimeHintsRegistrar implementation only if you need to register custom hints:
javaimport org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; public class MyRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { // Register reflection hints hints.reflection().registerType( MyClass.class, hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS) ); // Register resource hints hints.resources().registerPattern("custom-config/*.properties"); // Register serialization hints hints.serialization().registerType(MySerializableClass.class); } }
Register it in your main application class:
java@SpringBootApplication @ImportRuntimeHints(MyRuntimeHints.class) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Common Spring Boot Native Image Issues:
application.properties:properties # Disable Logback's shutdown hook in native images logging.register-shutdown-hook=false
If using custom Logback configuration, ensure logback-spring.xml is in resources and add to RuntimeHints: java hints.resources().registerPattern("logback-spring.xml"); hints.resources().registerPattern("org/springframework/boot/logging/logback/*.xml");
java hints.serialization().registerType(MyDto.class); hints.reflection().registerType( MyDto.class, hint -> hint.withMembers( MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS ) );
Add Jackson mix-ins to reflection hints if used: java hints.reflection().registerType(MyMixIn.class);
xml <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> </dependency>
@RegisterForReflection annotation for reflection needsCommon Quarkus Native Image Tips:
java @RegisterForReflection(targets = {MyClass.class, MyDto.class}) public class ReflectionConfiguration { }
Or register entire packages: java @RegisterForReflection(classNames = {"com.example.package.*"})
application.properties:properties quarkus.native.resources.includes=config/*.json,templates/** quarkus.native.additional-build-args=--initialize-at-run-time=com.example.RuntimeClass
xml <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-jdbc-postgresql</artifactId> </dependency>
properties quarkus.native.additional-build-args=--initialize-at-build-time=com.example.BuildTimeClass quarkus.native.additional-build-args=--initialize-at-run-time=com.example.RuntimeClass
properties quarkus.native.container-build=true quarkus.native.builder-image=mandrel
@ReflectionConfig and @Introspected annotations as neededCommon Micronaut Native Image Tips:
@Introspected for POJOs to avoid reflection:java @Introspected public class MyDto { private String name; private int value; // getters and setters }
Or enable package-wide introspection in application.yml: yaml micronaut: introspection: packages:
java @ReflectionConfig( type = MyClass.class, accessType = ReflectionConfig.AccessType.ALL_DECLARED_CONSTRUCTORS ) public class MyConfiguration { }
java @ResourceConfig( includes = {"application.yml", "logback.xml"} ) public class ResourceConfiguration { }
build.gradle:groovy graalvmNative { binaries { main { buildArgs.add("--initialize-at-build-time=io.micronaut") buildArgs.add("--initialize-at-run-time=io.netty") buildArgs.add("--report-unsupported-elements-at-runtime") } } }
yaml micronaut: http: client: read-timeout: 30s netty: default: allocator: max-order: 3
--no-fallback to catch all native image issuesresource-config.json--gc=serial (default) or --gc=epsilon (no-op GC for testing) and analyze dependencies| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +27 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.