I have a basic micronaut CRUD application which manages contacts through a Rest API. When running the app locally using graalvm-ce 21.0.2, the API returns the contact response as expected.
When I package the app using native packaging (docker-native or native-image) using:
mvn clean compile package -Dpackaging=native-image, my app doesn't return the Contact entity with all the properties
This is how the ContactResponse POJO looks like:
@Builder
public record ContactResponse(
String id,
String name,
String address,
String phoneNumber,
String email,
@JsonFormat(pattern = ObjectMapperConfig.API_DATE_TIME_PATTERN)
LocalDateTime createdAt
)
And calling the API (after packaging) returns:
{
"createdAt": "2025-10-14T12:35:41"
}
Adding @JsonProperty() to a field makes it appear in the response. After doing some research, i found that during the native executable building, graalvm compiler removes all items which are "not needed", including Reflective access, for performance reasons.
Since i'm using Jackson databind in my project, which relies on Java Reflection, I made it work by adding @ReflectiveAccess to force the compiler to generate reflection metadata for that specific object (ContactResponse)
I'd like to know if there's a way to reproduce this issue during the development process (and not during the packaging) so that my tests fail before i package and deploy. My tests are happening before i package the app into a native executable and thus can't discover this in advance.
After doing alot of investigation, i found that it was possible to execute the tests in a native runtime using the native-maven-plugin
Step 1: Configuring the native-maven-plugin in the pom.xml:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.3</version>
<configuration>
<!-- <1> -->
<imageName>contact-microservice-graalvm</imageName>
<buildArgs>
<!-- <2> -->
<buildArg>-Ob</buildArg>
</buildArgs>
</configuration>
</plugin>
Step 2: Running the following commands:
mvn clean compile package -Dpackaging=native-image (generating artifacts + test files)
mvn native:test (running the tests in the native runtime)
It would be nice if this could be mentioned in the official documentation / guides of micronaut. It could save alot of time.