This repository demonstrates building layered images with Micronaut.
- A GraalVM build with the Micronaut Hack patch applied, PR 18329 using:
cd graal/vm
mx --env svm build
mx --env svm graalvm-home
- make sure you have a JDK 21 installed
The custom Micronaut build will use a temporary repository containing the snapshot GraalVM SDK. To generate this repository, do the following:
cd graal/sdk
mx build
mx maven-deploy --licenses UPL,BSD-new,GPLv2-CPE foo file:///tmp/repo
This will create a Maven repository with the artifacts under /tmp/repo
.
git clone git@github.com:micronaut-projects/micronaut-core.git
cd micronaut-core
git checkout cc/layered-images-4.5
export JAVA_HOME=/path/to/your/java-21
andexport GRAALVM_HOME=/path/to/your/patched/graalvm-jdk
./gradlew pTML
The last step will build Micronaut 4.5.3 with a patch which allows running with layered images and publish the artifacts in the local Maven repository.
That custom version is named 4.5.3-li
.
Now everything should be available for this project to run. Make sure to:
export JAVA_HOME=/path/to/your/java-21
export GRAALVM_HOME=/path/to/your/patched/graalvm-jdk
Then you should be able to run the application without layered images support by running:
./gradlew nativeRun
And with layered images support by running:
./gradlew nativeCompile --use-layers nativeRun