← All notes

GraalVM native image gotchas

Written 10 Oct 2026

Native images start in milliseconds and use a fraction of the memory, but the closed-world assumption bites in surprising places.

Reflection needs config

Anything loaded by reflection (Jackson, Spring proxies) must be declared up front. Run the tracing agent against your test suite to generate it:

java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar app.jar

Static initialisers run at build time

If a class reads an env var in a static {} block and it’s initialised at build time, the value gets baked into the binary. Mark it --initialize-at-run-time.

💡 Still exploring

More notes coming as I migrate more services.

← Back to the notebook