AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

java-add-graalvm-native-image-support

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 quarkus-native-and-container skill.

Original source
github
License
MIT
Pinned revision
5269f7ea2d6c3a9bfda5ed878b6726cf509121fd

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read github--java-add-graalvm-native-image-support at revision 5269f7ea2d6c3a9bfda5ed878b6726cf509121fd, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 7

references/micronaut.md

Micronaut native images

Micronaut performs ahead-of-time processing at compile time, so most native image metadata is generated automatically.

Commands

  • Maven: ./mvnw package -Dpackaging=native-image (container build: ./mvnw package -Dpackaging=docker-native)
  • Gradle: ./gradlew nativeCompile (container: ./gradlew dockerBuildNative)
  • Native tests: ./mvnw -Pnative test or ./gradlew nativeTest, depending on the generated project

Check the generated project's profiles/tasks and use a compatible GraalVM JDK. In the standard Micronaut parent POM (4.10.0 and 5.0.2), graalvm configures annotation processing; native binds the Native Build Tools native-test goals. A successful -Pgraalvm test alone is not evidence that native tests ran.

The Micronaut Maven/Gradle plugins configure the Native Build Tools plugin for you; do not add it again.

Reflection and resources

  1. Bean introspection: @Introspected for POJOs avoids reflection:

    @Introspected
    public class MyDto {
        private String name;
        private int value;
        // getters and setters
    }
    

    Or @Serdeable for Micronaut Serialization types.

  2. Reflection: @ReflectionConfig(type = MyClass.class, accessType = TypeHint.AccessType.ALL_DECLARED_CONSTRUCTORS) (both from io.micronaut.core.annotation; accessType takes TypeHint.AccessType[]) on a configuration class, or @TypeHint(MyClass.class) for the default access.

  3. Resources: Micronaut has no resource annotation; list patterns in META-INF/native-image/<group>/<artifact>/resource-config.json (or the unified reachability-metadata.json), or use the Native Build Tools resource detection settings.

  4. Gradle build arguments (only if needed):

    graalvmNative {
        binaries {
            main {
                buildArgs.add("--initialize-at-run-time=io.netty")
            }
        }
    }
    

    Micronaut already sets sensible initialization defaults; add flags only for a specific failing class. Avoid --report-unsupported-elements-at-runtime outside diagnosis.

Tips

  • Use Micronaut's compile-time features (@Introspected, @Serdeable, @Client interfaces) rather than runtime reflection.
  • Netty and HTTP client tuning is a runtime concern; do not change netty.default.allocator settings to fix native build errors.
  • Check whether a compatible Micronaut module update supplies metadata before adding it manually; propose any upgrade for user approval, preserve managed versions, and rerun the JVM baseline afterwards.

Guide: https://docs.micronaut.io/latest/guide/#graal