agentleFS
GitHubKnown publishergithub/awesome-copilot/skills/java-add-graalvm-native-image-support/SKILL.md

java-add-graalvm-native-image-support

Skill40k starsChanged 2 months agoMITView on GitHub

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.

Trending

More talk lately.about the whole repository

Dec 2025: 8 mentionsJan 2026: 4 mentionsFeb 2026: 5 mentionsMar 2026: 9 mentionsApr 2026: 4 mentionsMay 2026: 2 mentionsJun 2026: 2 mentionsJul 2026: 2 mentionsAug 2026: 4 mentionsSep 2026: 8 mentionsOct 2026: 4 mentionsNov 2026: 3 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the github/awesome-copilot repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about github/awesome-copilot

The biggest 5 of 79 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 79

Talked about on Bluesky, GitHub and Hacker News (79 times).

On Bluesky · 42

37 more on Bluesky

On GitHub · 32

27 more on GitHub

The file

Show its rules and text

We split this skill into the rules it gives an agent

38 rules. About 0 are common, 25 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈25

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add appropriate GraalVM native image configuration

    line 12
  2. Distinctive:

    Follow Oracle's best practices for GraalVM native images and use an iterative approach to resolve issues.

    line 19
  3. Very specific:

    Check if pom.xml exists (Maven) or build.gradle/build.gradle.kts exists (Gradle)

    line 23
  4. Distinctive:

    Check for existing GraalVM configuration

    line 28
  5. Very specific:

    Add the GraalVM Native Build Tools plugin within a native profile in pom.xml:

    line 34
  6. Very specific:

    Add the GraalVM Native Build Tools plugin to build.gradle:

    line 85
  7. Distinctive:

    Run the appropriate build command:

    line 123
  8. Very specific:

    If you see errors about missing reflection configuration, create or update src/main/resources/META-INF/native-image/reflect-config.json:

    line 155
  9. Distinctive:

    After each fix, rebuild the native image

    line 208
  10. Distinctive:

    Use the GraalVM tracing agent to automatically generate configuration:

    line 210
  11. Distinctive:

    Test the native executable to ensure it runs correctly

    line 219
  12. Distinctive:

    Verify startup time improvements

    line 220
  13. Distinctive:

    Test all critical application paths

    line 222
  14. Distinctive:

    Ensure you're using compatible Spring Boot version (3.0+)

    line 228
  15. Distinctive:

    Test with Spring AOT processing enabled

    line 230
  16. Very specific:

    Create a RuntimeHintsRegistrar implementation only if you need to register custom hints:

    line 234
  17. Very specific:

    Logback Configuration: Add to application.properties:

    line 273
  18. Very specific:

    If using custom Logback configuration, ensure logback-spring.xml is in resources and add to RuntimeHints:

    line 279
  19. Distinctive:

    Add Jackson mix-ins to reflection hints if used:

    line 297
  20. Distinctive:

    Jackson Modules: Ensure Jackson modules are on the classpath:

    line 302
  21. Very specific:

    Use @RegisterForReflection annotation for reflection needs

    line 312
  22. Distinctive:

    Reflection Registration: Use annotations instead of manual configuration:

    line 317
  23. Very specific:

    Resource Inclusion: Add to application.properties:

    line 329
  24. Distinctive:

    Database Drivers: Ensure you're using Quarkus-supported JDBC extensions:

    line 335
  25. Distinctive:

    Container Image Build: Use Quarkus container-image extensions:

    line 349
  26. Very specific:

    Use @ReflectionConfig and @Introspected annotations as needed

    line 357
  27. Very specific:

    Bean Introspection: Use @Introspected for POJOs to avoid reflection:

    line 362
  28. Distinctive:

    Reflection Configuration: Use declarative annotations:

    line 380
  29. Distinctive:

    Resource Configuration: Add resources to native image:

    line 390
  30. Distinctive:

    Use Tracing Agent: Run your application with the GraalVM tracing agent to automatically discover reflection, resources, and JNI requirements

    line 427
  31. Distinctive:

    Minimize Reflection: Prefer compile-time code generation over runtime reflection

    line 429
  32. Distinctive:

    CI/CD Integration: Add native image builds to your CI/CD pipeline

    line 431
  33. Distinctive:

    Keep Dependencies Updated: Use latest versions for better GraalVM compatibility

    line 432
  34. Distinctive:

    Build Fails with Reflection Errors: Use the tracing agent or add manual reflection configuration

    line 436
  35. Very specific:

    Missing Resources: Ensure resource patterns are correctly specified in resource-config.json

    line 437
  36. Distinctive:

    ClassNotFoundException at Runtime: Add the class to reflection configuration

    line 438
  37. Distinctive:

    Slow Build Times: Consider using build caching and incremental builds

    line 439
  38. Very specific:

    Large Image Size: Use --gc=serial (default) or --gc=epsilon (no-op GC for testing) and analyze dependencies

    line 440

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

GraalVM Native Image Agent

You are an expert in adding GraalVM native image support to Java applications. Your goal is to:

  1. Analyze the project structure and identify the build tool (Maven or Gradle)
  2. Detect the framework (Spring Boot, Quarkus, Micronaut, or generic Java)
  3. Add appropriate GraalVM native image configuration
  4. Build the native image
  5. Analyze any build errors or warnings
  6. Apply fixes iteratively until the build succeeds

Your Approach

Follow Oracle's best practices for GraalVM native images and use an iterative approach to resolve issues.

Step 1: Analyze the Project

  • Check if pom.xml exists (Maven) or build.gradle/build.gradle.kts exists (Gradle)
  • Identify the framework by checking dependencies:
    • Spring Boot: spring-boot-starter dependencies
    • Quarkus: quarkus- dependencies
    • Micronaut: micronaut- dependencies
  • Check for existing GraalVM configuration

Step 2: Add Native Image Support

For Maven Projects

Add the GraalVM Native Build Tools plugin within a native profile in pom.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:

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

For Gradle Projects

Add the GraalVM Native Build Tools plugin to build.gradle:

plugins {
  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):

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")
    }
  }
}

Step 3: Build the Native Image

Run the appropriate build command:

Maven:

mvn -Pnative native:compile

Gradle:

./gradlew nativeCompile

Spring Boot (Maven):

mvn -Pnative spring-boot:build-image

Quarkus (Maven):

./mvnw package -Pnative

Micronaut (Maven):

./mvnw package -Dpackaging=native-image

Step 4: Analyze Build Errors

Common issues and solutions:

Reflection Issues

If you see errors about missing reflection configuration, create or update src/main/resources/META-INF/native-image/reflect-config.json:

[
  {
    "name": "com.example.YourClass",
    "allDeclaredConstructors": true,
    "allDeclaredMethods": true,
    "allDeclaredFields": true
  }
]

Resource Access Issues

For missing resources, create src/main/resources/META-INF/native-image/resource-config.json:

{
  "resources": {
    "includes": [
      {"pattern": "application.properties"},
      {"pattern": ".*\\.yml"},
      {"pattern": ".*\\.yaml"}
    ]
  }
}

JNI Issues

For JNI-related errors, create src/main/resources/META-INF/native-image/jni-config.json:

[
  {
    "name": "com.example.NativeClass",
    "methods": [
      {"name": "nativeMethod", "parameterTypes": ["java.lang.String"]}
    ]
  }
]

Dynamic Proxy Issues

For dynamic proxy errors, create src/main/resources/META-INF/native-image/proxy-config.json:

[
  ["com.example.Interface1", "com.example.Interface2"]
]

Step 5: Iterate Until Success

  • After each fix, rebuild the native image
  • Analyze new errors and apply appropriate fixes
  • Use the GraalVM tracing agent to automatically generate configuration:
    java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar target/app.jar
  • Continue until the build succeeds without errors

Step 6: Verify the Native Image

Once built successfully:

  • Test the native executable to ensure it runs correctly
  • Verify startup time improvements
  • Check memory footprint
  • Test all critical application paths

Framework-Specific Considerations

Spring Boot

  • Spring Boot 3.0+ has excellent native image support
  • Ensure you're using compatible Spring Boot version (3.0+)
  • Most Spring libraries provide GraalVM hints automatically
  • Test with Spring AOT processing enabled

When to Add Custom RuntimeHints:

Create a RuntimeHintsRegistrar implementation only if you need to register custom hints:

import 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:

@SpringBootApplication
@ImportRuntimeHints(MyRuntimeHints.class)
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Common Spring Boot Native Image Issues:

  1. Logback Configuration: Add to application.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:

    hints.resources().registerPattern("logback-spring.xml");
    hints.resources().registerPattern("org/springframework/boot/logging/logback/*.xml");
  2. Jackson Serialization: For custom Jackson modules or types, register them:

    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:

    hints.reflection().registerType(MyMixIn.class);
  3. Jackson Modules: Ensure Jackson modules are on the classpath:
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
    </dependency>

Quarkus

  • Quarkus is designed for native images with zero configuration in most cases
  • Use @RegisterForReflection annotation for reflection needs
  • Quarkus extensions handle GraalVM configuration automatically

Common Quarkus Native Image Tips:

  1. Reflection Registration: Use annotations instead of manual configuration:

    @RegisterForReflection(targets = {MyClass.class, MyDto.class})
    public class ReflectionConfiguration {
    }

    Or register entire packages:

    @RegisterForReflection(classNames = {"com.example.package.*"})
  2. Resource Inclusion: Add to application.properties:
    quarkus.native.resources.includes=config/*.json,templates/**
    quarkus.native.additional-build-args=--initialize-at-run-time=com.example.RuntimeClass
  3. Database Drivers: Ensure you're using Quarkus-supported JDBC extensions:
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
  4. Build-Time vs Runtime Initialization: Control initialization with:
    quarkus.native.additional-build-args=--initialize-at-build-time=com.example.BuildTimeClass
    quarkus.native.additional-build-args=--initialize-at-run-time=com.example.RuntimeClass
  5. Container Image Build: Use Quarkus container-image extensions:
    quarkus.native.container-build=true
    quarkus.native.builder-image=mandrel

Micronaut

  • Micronaut has built-in GraalVM support with minimal configuration
  • Use @ReflectionConfig and @Introspected annotations as needed
  • Micronaut's ahead-of-time compilation reduces reflection requirements

Common Micronaut Native Image Tips:

  1. Bean Introspection: Use @Introspected for POJOs to avoid reflection:

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

    Or enable package-wide introspection in application.yml:

    micronaut:
      introspection:
        packages:
          - com.example.dto
  2. Reflection Configuration: Use declarative annotations:
    @ReflectionConfig(
        type = MyClass.class,
        accessType = ReflectionConfig.AccessType.ALL_DECLARED_CONSTRUCTORS
    )
    public class MyConfiguration {
    }
  3. Resource Configuration: Add resources to native image:
    @ResourceConfig(
        includes = {"application.yml", "logback.xml"}
    )
    public class ResourceConfiguration {
    }
  4. Native Image Configuration: In build.gradle:
    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")
            }
        }
    }
  5. HTTP Client Configuration: For Micronaut HTTP clients, ensure netty is properly configured:
    micronaut:
      http:
        client:
          read-timeout: 30s
    netty:
      default:
        allocator:
          max-order: 3

Best Practices

  • Start Simple: Build with --no-fallback to catch all native image issues
  • Use Tracing Agent: Run your application with the GraalVM tracing agent to automatically discover reflection, resources, and JNI requirements
  • Test Thoroughly: Native images behave differently than JVM applications
  • Minimize Reflection: Prefer compile-time code generation over runtime reflection
  • Profile Memory: Native images have different memory characteristics
  • CI/CD Integration: Add native image builds to your CI/CD pipeline
  • Keep Dependencies Updated: Use latest versions for better GraalVM compatibility

Troubleshooting Tips

  1. Build Fails with Reflection Errors: Use the tracing agent or add manual reflection configuration
  2. Missing Resources: Ensure resource patterns are correctly specified in resource-config.json
  3. ClassNotFoundException at Runtime: Add the class to reflection configuration
  4. Slow Build Times: Consider using build caching and incremental builds
  5. Large Image Size: Use --gc=serial (default) or --gc=epsilon (no-op GC for testing) and analyze dependencies

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.