Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit updates how Micronaut AOT generates code for GraalVM 22. In 22, the new default is to forbid build time initialization of classes. Each class which is initialized at build time has to be explicitly declared as such. This commit makes it so that classes we generate and know are initialized at build time are added to the
--initialize-at-build-time
option.While this fixes a lot of cases, we cannot, unfortunately, kwow upfront all the dependencies of the types we initialize at build time, which may also need build time initialization. This means that in some cases, users will have to explicitly add some types to the list (e.g via a
buildArg
in the native binaries Gradle extension).Ideally, we should move AOT off build time initialization. However, this is not currently doable, since precisely Micronaut Core and optimization registration is designed to use static fields. An option would be to use service loading instead, but it's a breaking change, and that would remove the ability to have a service loading optimization. While removing the service loading optimization may not be an issue for native, it is, however, a problem for JIT optimizations.
There's therefore no good solution that I'm aware of to this problem.
Note: this problem was unnoticed because we don't have tests which try to build a native image with AOT optimizations on latest GraalVM. It would be good to have such tests somewhere. /cc @fniephaus