From 1a8a33d55c700e903335145b8182e8bc58a2d5e1 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Tue, 9 Dec 2025 10:26:14 +0100 Subject: [PATCH 01/12] Add GraalVM Native Image support for Java applications --- .../java-add-graalvm-native-image-support.md | 438 ++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 prompts/java-add-graalvm-native-image-support.md diff --git a/prompts/java-add-graalvm-native-image-support.md b/prompts/java-add-graalvm-native-image-support.md new file mode 100644 index 00000000..904b8a85 --- /dev/null +++ b/prompts/java-add-graalvm-native-image-support.md @@ -0,0 +1,438 @@ +--- +description: '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.' +tools: + - read_file + - replace_string_in_file + - run_in_terminal + - list_dir + - grep_search +--- + +# 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 to `pom.xml`: + +```xml + + org.graalvm.buildtools + native-maven-plugin + 0.10.0 + true + + + build-native + + compile-no-fork + + package + + + + ${project.artifactId} + + --no-fallback + + + +``` + +For Spring Boot projects, also ensure the Spring Boot Maven plugin is configured: + +```xml + + org.springframework.boot + spring-boot-maven-plugin + +``` + +#### For Gradle Projects + +Add the GraalVM Native Build Tools plugin to `build.gradle`: + +```groovy +plugins { + id 'org.graalvm.buildtools.native' version '0.10.0' +} + +graalvmNative { + binaries { + main { + imageName = project.name + buildArgs.add('--no-fallback') + } + } +} +``` + +Or for Kotlin DSL (`build.gradle.kts`): + +```kotlin +plugins { + id("org.graalvm.buildtools.native") version "0.10.0" +} + +graalvmNative { + binaries { + named("main") { + imageName.set(project.name) + buildArgs.add("--no-fallback") + } + } +} +``` + +### Step 3: Build the Native Image + +Run the appropriate build command: + +**Maven:** +```sh +mvn -Pnative native:compile +``` + +**Gradle:** +```sh +./gradlew nativeCompile +``` + +**Spring Boot (Maven):** +```sh +mvn -Pnative spring-boot:build-image +``` + +**Quarkus (Maven):** +```sh +./mvnw package -Pnative +``` + +**Micronaut (Maven):** +```sh +./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`: + +```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`: + +```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`: + +```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`: + +```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: + ```sh + 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: + +```java +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: + +```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:** + +1. **Logback Configuration**: Add to `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"); + ``` + +2. **Jackson Serialization**: For custom Jackson modules or types, register them: + ```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); + ``` + +3. **Jackson Modules**: Ensure Jackson modules are on the classpath: + ```xml + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + ``` + +### 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: + ```java + @RegisterForReflection(targets = {MyClass.class, MyDto.class}) + public class ReflectionConfiguration { + } + ``` + + Or register entire packages: + ```java + @RegisterForReflection(classNames = {"com.example.package.*"}) + ``` + +2. **Resource Inclusion**: Add to `application.properties`: + ```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: + ```xml + + io.quarkus + quarkus-jdbc-postgresql + + ``` + +4. **Build-Time vs Runtime Initialization**: Control initialization with: + ```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 + ``` + +5. **Container Image Build**: Use Quarkus container-image extensions: + ```properties + 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: + ```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: + - com.example.dto + ``` + +2. **Reflection Configuration**: Use declarative annotations: + ```java + @ReflectionConfig( + type = MyClass.class, + accessType = ReflectionConfig.AccessType.ALL_DECLARED_CONSTRUCTORS + ) + public class MyConfiguration { + } + ``` + +3. **Resource Configuration**: Add resources to native image: + ```java + @ResourceConfig( + includes = {"application.yml", "logback.xml"} + ) + public class ResourceConfiguration { + } + ``` + +4. **Native Image Configuration**: In `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") + } + } + } + ``` + +5. **HTTP Client Configuration**: For Micronaut HTTP clients, ensure netty is properly configured: + ```yaml + 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=G1` or `--gc=serial` and analyze dependencies + +## References + +- [GraalVM Native Image Documentation](https://www.graalvm.org/latest/reference-manual/native-image/) +- [Spring Boot Native Image Guide](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html) +- [Quarkus Building Native Images](https://quarkus.io/guides/building-native-image) +- [Micronaut GraalVM Support](https://docs.micronaut.io/latest/guide/index.html#graal) +- [GraalVM Reachability Metadata](https://github.com/oracle/graalvm-reachability-metadata) +- [Native Build Tools](https://graalvm.github.io/native-build-tools/latest/index.html) From 1bd5641d384c152eb8c092f5d0871f59b79ed441 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:36:19 +0100 Subject: [PATCH 02/12] Fix comments from @aaronpowell --- docs/README.prompts.md | 1 + ...upport.md => java-add-graalvm-native-image-support.prompt.md} | 0 2 files changed, 1 insertion(+) rename prompts/{java-add-graalvm-native-image-support.md => java-add-graalvm-native-image-support.prompt.md} (100%) diff --git a/docs/README.prompts.md b/docs/README.prompts.md index 20468baa..489a97d1 100644 --- a/docs/README.prompts.md +++ b/docs/README.prompts.md @@ -73,6 +73,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi | [Github Copilot Starter](../prompts/github-copilot-starter.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgithub-copilot-starter.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgithub-copilot-starter.prompt.md) | Set up complete GitHub Copilot configuration for a new project based on technology stack | | [GitHub Issue Planning & Project Automation Prompt](../prompts/breakdown-plan.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fbreakdown-plan.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fbreakdown-plan.prompt.md) | Issue Planning and Automation prompt that generates comprehensive project plans with Epic > Feature > Story/Enabler > Test hierarchy, dependencies, priorities, and automated tracking. | | [Go MCP Server Project Generator](../prompts/go-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgo-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgo-mcp-server-generator.prompt.md) | Generate a complete Go MCP server project with proper structure, dependencies, and implementation using the official github.com/modelcontextprotocol/go-sdk. | +| [GraalVM Native Image Agent](../prompts/java-add-graalvm-native-image-support.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-add-graalvm-native-image-support.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-add-graalvm-native-image-support.prompt.md) | 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. | | [Interactive Programming Nudge](../prompts/remember-interactive-programming.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fremember-interactive-programming.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fremember-interactive-programming.prompt.md) | A micro-prompt that reminds the agent that it is an interactive programmer. Works great in Clojure when Copilot has access to the REPL (probably via Backseat Driver). Will work with any system that has a live REPL that the agent can use. Adapt the prompt with any specific reminders in your workflow and/or workspace. | | [Java Documentation (Javadoc) Best Practices](../prompts/java-docs.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-docs.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-docs.prompt.md) | Ensure that Java types are documented with Javadoc comments and follow best practices for documentation. | | [Java MCP Server Generator](../prompts/java-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-mcp-server-generator.prompt.md) | Generate a complete Model Context Protocol server project in Java using the official MCP Java SDK with reactive streams and optional Spring Boot integration. | diff --git a/prompts/java-add-graalvm-native-image-support.md b/prompts/java-add-graalvm-native-image-support.prompt.md similarity index 100% rename from prompts/java-add-graalvm-native-image-support.md rename to prompts/java-add-graalvm-native-image-support.prompt.md From 16ef3cbf7b036c6f6a56bda8aae334761b66551b Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:40:33 +0100 Subject: [PATCH 03/12] Use [latest-version] placeholder --- ...-add-graalvm-native-image-support.prompt.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 904b8a85..9ae4852c 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -42,7 +42,7 @@ Add the GraalVM Native Build Tools plugin to `pom.xml`: org.graalvm.buildtools native-maven-plugin - 0.10.0 + [latest-version] true @@ -77,7 +77,7 @@ Add the GraalVM Native Build Tools plugin to `build.gradle`: ```groovy plugins { - id 'org.graalvm.buildtools.native' version '0.10.0' + id 'org.graalvm.buildtools.native' version '[latest-version]' } graalvmNative { @@ -94,7 +94,7 @@ Or for Kotlin DSL (`build.gradle.kts`): ```kotlin plugins { - id("org.graalvm.buildtools.native") version "0.10.0" + id("org.graalvm.buildtools.native") version "[latest-version]" } graalvmNative { @@ -235,10 +235,10 @@ public class MyRuntimeHints implements RuntimeHintsRegistrar { 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); } @@ -264,7 +264,7 @@ public class Application { # 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"); @@ -282,7 +282,7 @@ public class Application { ) ); ``` - + Add Jackson mix-ins to reflection hints if used: ```java hints.reflection().registerType(MyMixIn.class); @@ -309,7 +309,7 @@ public class Application { public class ReflectionConfiguration { } ``` - + Or register entire packages: ```java @RegisterForReflection(classNames = {"com.example.package.*"}) @@ -357,7 +357,7 @@ public class Application { // getters and setters } ``` - + Or enable package-wide introspection in `application.yml`: ```yaml micronaut: From 96c7b84ebc58c1c55c3cacdca65bba085b0a7394 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:43:24 +0100 Subject: [PATCH 04/12] Update prompts/java-add-graalvm-native-image-support.prompt.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- prompts/java-add-graalvm-native-image-support.prompt.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 9ae4852c..ab1150eb 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -213,8 +213,8 @@ Once built successfully: ## Framework-Specific Considerations ### Spring Boot -- Spring Boot 3.0+ has excellent native image support -- Ensure you're using compatible Spring Boot version (3.0+) +- Spring Boot 3.2+ is recommended for best native image support (with enhanced capabilities and improved compatibility) +- Minimum required version is Spring Boot 3.0, but 3.2 or later is strongly advised - Most Spring libraries provide GraalVM hints automatically - Test with Spring AOT processing enabled From 8c25aeda5dda757183f6d9e6f005ec753a1ccb7b Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:44:31 +0100 Subject: [PATCH 05/12] Update prompts/java-add-graalvm-native-image-support.prompt.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- prompts/java-add-graalvm-native-image-support.prompt.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index ab1150eb..1a638e06 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -312,7 +312,10 @@ public class Application { Or register entire packages: ```java - @RegisterForReflection(classNames = {"com.example.package.*"}) + // Wildcards are NOT supported; list each class explicitly: + @RegisterForReflection(classNames = {"com.example.package.Foo", "com.example.package.Bar"}) + // Or, preferably, use the targets attribute with class references: + @RegisterForReflection(targets = {com.example.package.Foo.class, com.example.package.Bar.class}) ``` 2. **Resource Inclusion**: Add to `application.properties`: From 28e00d41c20cdb90fefd9371eddd1452479c598e Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:45:02 +0100 Subject: [PATCH 06/12] Update prompts/java-add-graalvm-native-image-support.prompt.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- prompts/java-add-graalvm-native-image-support.prompt.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 1a638e06..ce9304c5 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -162,8 +162,8 @@ For missing resources, create `src/main/resources/META-INF/native-image/resource "resources": { "includes": [ {"pattern": "application.properties"}, - {"pattern": ".*\\.yml"}, - {"pattern": ".*\\.yaml"} + {"pattern": ".*\\\\.yml"}, + {"pattern": ".*\\\\.yaml"} ] } } From 2db9ed307b84e95443ce1659a6ff81dc6a15b5b2 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:45:35 +0100 Subject: [PATCH 07/12] Update prompts/java-add-graalvm-native-image-support.prompt.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- prompts/java-add-graalvm-native-image-support.prompt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index ce9304c5..7bebbc43 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -341,7 +341,7 @@ public class Application { 5. **Container Image Build**: Use Quarkus container-image extensions: ```properties quarkus.native.container-build=true - quarkus.native.builder-image=mandrel + quarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 ``` ### Micronaut From 561da504d1fe179387dc41ee19da2bc7cd783e65 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:49:16 +0100 Subject: [PATCH 08/12] Add model for GraalVM native build --- ...va-add-graalvm-native-image-support.prompt.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 7bebbc43..93780fd5 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -1,5 +1,6 @@ --- description: '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.' +model: 'Claude Sonnet 4.5' tools: - read_file - replace_string_in_file @@ -162,8 +163,8 @@ For missing resources, create `src/main/resources/META-INF/native-image/resource "resources": { "includes": [ {"pattern": "application.properties"}, - {"pattern": ".*\\\\.yml"}, - {"pattern": ".*\\\\.yaml"} + {"pattern": ".*\\.yml"}, + {"pattern": ".*\\.yaml"} ] } } @@ -213,8 +214,8 @@ Once built successfully: ## Framework-Specific Considerations ### Spring Boot -- Spring Boot 3.2+ is recommended for best native image support (with enhanced capabilities and improved compatibility) -- Minimum required version is Spring Boot 3.0, but 3.2 or later is strongly advised +- 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 @@ -312,10 +313,7 @@ public class Application { Or register entire packages: ```java - // Wildcards are NOT supported; list each class explicitly: - @RegisterForReflection(classNames = {"com.example.package.Foo", "com.example.package.Bar"}) - // Or, preferably, use the targets attribute with class references: - @RegisterForReflection(targets = {com.example.package.Foo.class, com.example.package.Bar.class}) + @RegisterForReflection(classNames = {"com.example.package.*"}) ``` 2. **Resource Inclusion**: Add to `application.properties`: @@ -341,7 +339,7 @@ public class Application { 5. **Container Image Build**: Use Quarkus container-image extensions: ```properties quarkus.native.container-build=true - quarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 + quarkus.native.builder-image=mandrel ``` ### Micronaut From 6877ac912b4744a860387338f5f9c5330da61439 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:51:56 +0100 Subject: [PATCH 09/12] Update prompts/java-add-graalvm-native-image-support.prompt.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- prompts/java-add-graalvm-native-image-support.prompt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 93780fd5..06fed671 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -427,7 +427,7 @@ public class Application { 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=G1` or `--gc=serial` and analyze dependencies +5. **Large Image Size**: Use `--gc=serial` (default) or `--gc=epsilon` (no-op GC for testing) and analyze dependencies ## References From 9667176d3ee808b1b66a50f203a5ba71c05ae48f Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 16:54:20 +0100 Subject: [PATCH 10/12] specify agent mode --- prompts/java-add-graalvm-native-image-support.prompt.md | 1 + 1 file changed, 1 insertion(+) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 06fed671..09b21f11 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -1,4 +1,5 @@ --- +agent: 'agent' description: '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.' model: 'Claude Sonnet 4.5' tools: From 91688d9fa6592482665cb4640143882f0bfdd3e1 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 17:18:20 +0100 Subject: [PATCH 11/12] Enhance GraalVM Native Image support in Maven configuration by adding a native profile and specifying main class for better build management --- ...add-graalvm-native-image-support.prompt.md | 70 ++++++++++++------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index 09b21f11..acfdfec3 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -38,39 +38,53 @@ Follow Oracle's best practices for GraalVM native images and use an iterative ap #### For Maven Projects -Add the GraalVM Native Build Tools plugin to `pom.xml`: +Add the GraalVM Native Build Tools plugin within a `native` profile in `pom.xml`: ```xml - - org.graalvm.buildtools - native-maven-plugin - [latest-version] - true - - - build-native - - compile-no-fork - - package - - - - ${project.artifactId} - - --no-fallback - - - + + + native + + + + org.graalvm.buildtools + native-maven-plugin + [latest-version] + true + + + build-native + + compile-no-fork + + package + + + + ${project.artifactId} + ${main.class} + + --no-fallback + + + + + + + ``` -For Spring Boot projects, also ensure the Spring Boot Maven plugin is configured: +For Spring Boot projects, ensure the Spring Boot Maven plugin is in the main build section: ```xml - - org.springframework.boot - spring-boot-maven-plugin - + + + + org.springframework.boot + spring-boot-maven-plugin + + + ``` #### For Gradle Projects @@ -86,6 +100,7 @@ graalvmNative { binaries { main { imageName = project.name + mainClass = application.mainClass.get() buildArgs.add('--no-fallback') } } @@ -103,6 +118,7 @@ graalvmNative { binaries { named("main") { imageName.set(project.name) + mainClass.set(application.mainClass.get()) buildArgs.add("--no-fallback") } } From a24145a910351bd30b8ff1f319261f3ff7046866 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 10 Dec 2025 17:24:48 +0100 Subject: [PATCH 12/12] Fix formatting of agent field in GraalVM Native Image support prompt --- prompts/java-add-graalvm-native-image-support.prompt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompts/java-add-graalvm-native-image-support.prompt.md b/prompts/java-add-graalvm-native-image-support.prompt.md index acfdfec3..1a394074 100644 --- a/prompts/java-add-graalvm-native-image-support.prompt.md +++ b/prompts/java-add-graalvm-native-image-support.prompt.md @@ -1,5 +1,5 @@ --- -agent: 'agent' +agent: agent description: '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.' model: 'Claude Sonnet 4.5' tools: