13.4.2 GraalVM and Micronaut FAQ

How does Micronaut manage to run on GraalVM?

Micronaut features a Dependency Injection and Aspect-Oriented Programming runtime that uses no reflection. This makes it easier for Micronaut applications to run on GraalVM since there are limitations particularly around reflection on SubstrateVM.

How can I make a Micronaut application that uses picocli run on GraalVM?

Picocli provides a picocli-codegen module with a tool for generating a GraalVM reflection configuration file. The tool can be run manually or automatically as part of the build. The module’s README has usage instructions with code snippets for configuring Gradle and Maven to generate a cli-reflect.json file automatically as part of the build. Add the generated file to the -H:ReflectionConfigurationFiles option when running the native-image tool.

What about other Third-Party Libraries?

Micronaut cannot guarantee that third-party libraries work on GraalVM SubstrateVM, that is down to each individual library to implement support.

I Get a “Class XXX is instantiated reflectively…​” Exception. What do I do?

If you get an error such as:

  1. Class myclass.Foo[] is instantiated reflectively but was never registered. Register the class by using org.graalvm.nativeimage.RuntimeReflection

You may need to manually tweak the generated reflect.json file. For regular classes you need to add an entry into the array:

  1. [
  2. {
  3. "name" : "myclass.Foo",
  4. "allDeclaredConstructors" : true
  5. },
  6. ...
  7. ]

For arrays this needs to use the Java JVM internal array representation. For example:

  1. [
  2. {
  3. "name" : "[Lmyclass.Foo;",
  4. "allDeclaredConstructors" : true
  5. },
  6. ...
  7. ]

14 Management & Monitoring

Using the CLI

If you are creating your project using the Micronaut CLI, supply the management feature to configure the management endpoints in your project:

  1. $ mn create-app my-app features management

Inspired by Spring Boot and Grails, the Micronaut management dependency adds support for monitoring of your application via endpoints: special URIs that return details about the health and state of your application. The management endpoints are also integrated with Micronaut’s security dependency, allowing for sensitive data to be restricted to authenticated users in your security system (see Built-in Endpoints Access in the Security section).

To use the management features described in this section, add the dependency on your classpath.

  1. implementation("io.micronaut:micronaut-management")
  1. <dependency>
  2. <groupId>io.micronaut</groupId>
  3. <artifactId>micronaut-management</artifactId>
  4. </dependency>