native-maven-plugin: combine reachability metadata with custom reflection config and predefined classes

23 Views Asked by At

I have a Spring MVC 5 fat jar made with maven-shade-plugin. I'm now trying to build a native image from it. I've run native-image-agent on it and spot some missing reflection calls and got a list of 'agent-extracted-predefined-classes'. The app itself has a huge number of dependencies and I would like to use publicly available reachability metadata.

I've read through a lot of posts but I've failed to nail how to achieve this:

  1. Point native-maven-plugin to existing .jar (ideally)
  2. Tell plugin to use my own reflect-config.json plus reachability metadata
  3. Somehow pick-up existing predefined-classes-config.json (should I include it into jar so native-image will pick-it up automatically?)
  4. Be able to run native-agent as a part of build (optional)

Which version of plugin show I use? Is my graalvm too old?

I'm using graalvm-ce-21.0.2.

Thanks.

Here is the list of sources that I've checked:

https://www.graalvm.org/22.1/reference-manual/native-image/ExperimentalAgentOptions/ https://www.graalvm.org/latest/reference-manual/native-image/metadata/ https://github.com/spring-projects/spring-boot/issues/35659 https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#metadata-support https://graalvm.github.io/native-build-tools/latest/maven-plugin-quickstart.html https://medium.com/graalvm/simplifying-native-image-generation-with-maven-plugin-and-embeddable-configuration-d5b283b92f57 https://www.graalvm.org/22.2/reference-manual/native-image/guides/use-native-image-maven-plugin/

UPD: I've managed to get work 1,2 by using this setup:

<plugin>
            <groupId>org.graalvm.buildtools</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <version>0.10.1</version>
            <configuration>
                <fallback>false</fallback>
                <mainClass>launch.Main</mainClass>
                <classpath>${project.build.directory}/ROOT.jar</classpath>
                <metadataRepository>
                    <enabled>true</enabled>
                </metadataRepository>
                <verbose>true</verbose>
            </configuration>
            <executions>
                <execution>
                    <id>build-native</id>
                    <goals>
                        <goal>compile-no-fork</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <buildArgs>
                            <buildArg>--report-unsupported-elements-at-runtime</buildArg>
                            <buildArg>-H:ReflectionConfigurationFiles=native-image/conf/reflect-config-custom.json</buildArg>
                            <buildArg>-H:ResourceConfigurationFiles=native-image/conf/resource-config-custom.json</buildArg>
                            <buildArg>--enable-all-security-services</buildArg>
                            <buildArg>--enable-http</buildArg>
                            <buildArg>--enable-https</buildArg>
                        </buildArgs>
                        <jvmArgs>
                            <arg>--add-opens=java.base/java.lang=ALL-UNNAMED</arg>
                            <arg>--add-opens=java.base/java.io=ALL-UNNAMED</arg>
                            <arg>--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED</arg>
                            <arg>-Dspring.profiles.active=ad</arg>
                        </jvmArgs>
                        <pluginArtifacts>
                            <pluginArtifact>
                                <file>${project.build.directory}/ROOT.jar</file>
                                <type>jar</type>
                            </pluginArtifact>
                        </pluginArtifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Any ideas about predefined classes? Or I miss the concept of it?

UPD2: Looks like -H:ConfigurationFileDirectories= does the trick for #2, #3.

So this could be closed then.

0

There are 0 best solutions below