From ff63dd6fd480408c61fc5031ee48e9b95eab58b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Mon, 15 Jan 2024 09:34:28 +0100 Subject: [PATCH 1/2] Update native configuration file best practices * Update to promote best ways to use custom configuration files. --- .../writing-native-applications-tips.adoc | 58 +------------------ 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/docs/src/main/asciidoc/writing-native-applications-tips.adoc b/docs/src/main/asciidoc/writing-native-applications-tips.adoc index 1c03cea02b2cf..08c198bedaeff 100644 --- a/docs/src/main/asciidoc/writing-native-applications-tips.adoc +++ b/docs/src/main/asciidoc/writing-native-applications-tips.adoc @@ -60,7 +60,9 @@ will include: ==== Using a configuration file If globs are not sufficiently precise for your use case and you need to rely on regular expressions, or if you prefer relying on the GraalVM infrastructure, -you can also create a `resource-config.json` (the most common location is within `src/main/resources`) JSON file defining which resources should be included. +you can also create a `resource-config.json` JSON file defining which resources should be included. +Ideally this, and other native image configuration files, should be placed under the `src/main/resources/META-INF/native-image//` folder. +By placing them there, there is no additional configuration parameters that need to be passed into the native build. [WARNING] ==== @@ -93,60 +95,6 @@ Here we include all the XML files and JSON files into the native executable. For more information about this topic, see the link:https://www.graalvm.org/{graalvm-docs-version}/reference-manual/native-image/dynamic-features/Resources/[GraalVM Accessing Resources in Native Image] guide. ==== -The final order of business is to make the configuration file known to the `native-image` executable by adding the proper configuration to `application.properties`: - -[source,properties] ----- -quarkus.native.additional-build-args =\ - -H:+UnlockExperimentalVMOptions,\ - -H:ResourceConfigurationFiles=resource-config.json,\ - -H:-UnlockExperimentalVMOptions ----- - -[NOTE] -==== -Starting with Mandrel 23.1 and GraalVM for JDK 21, `-H:ResourceConfigurationFiles=resource-config.json` results in a warning being shown unless wrapped in `-H:+UnlockExperimentalVMOptions` and `-H:-UnlockExperimentalVMOptions`. -The absence of these options will result in build failures in the future. -==== - -In the previous snippet we were able to simply use `resource-config.json` instead of specifying the entire path of the file simply because it was added to `src/main/resources`. -If the file had been added to another directory, the proper file path would have had to be specified manually. - -[TIP] -==== -Multiple options may be separated by a comma. For example, one could use: - -[source,properties] ----- -quarkus.native.additional-build-args =\ - -H:+UnlockExperimentalVMOptions,\ - -H:ResourceConfigurationFiles=resource-config.json,\ - -H:ReflectionConfigurationFiles=reflect-config.json,\ - -H:-UnlockExperimentalVMOptions ----- - -in order to ensure that various resources are included and additional reflection is registered. - -==== -If for some reason adding the aforementioned configuration to `application.properties` is not desirable, it is possible to configure the build tool to effectively perform the same operation. - -When using Maven, we could use the following configuration: - -[source,xml] ----- - - - native - - native - - -H:+UnlockExperimentalVMOptions,-H:ResourceConfigurationFiles=resource-config.json,-H:-UnlockExperimentalVMOptions - - - - ----- - === Registering for reflection When building a native executable, GraalVM operates with a closed world assumption. From c575a2df14a534d586c002795447e6b644f35556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarre=C3=B1o?= Date: Fri, 9 Feb 2024 17:01:58 +0100 Subject: [PATCH 2/2] Update docs/src/main/asciidoc/writing-native-applications-tips.adoc Co-authored-by: Foivos --- docs/src/main/asciidoc/writing-native-applications-tips.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/writing-native-applications-tips.adoc b/docs/src/main/asciidoc/writing-native-applications-tips.adoc index 08c198bedaeff..df6066231f32a 100644 --- a/docs/src/main/asciidoc/writing-native-applications-tips.adoc +++ b/docs/src/main/asciidoc/writing-native-applications-tips.adoc @@ -62,7 +62,7 @@ will include: If globs are not sufficiently precise for your use case and you need to rely on regular expressions, or if you prefer relying on the GraalVM infrastructure, you can also create a `resource-config.json` JSON file defining which resources should be included. Ideally this, and other native image configuration files, should be placed under the `src/main/resources/META-INF/native-image//` folder. -By placing them there, there is no additional configuration parameters that need to be passed into the native build. +This way they will be automatically parsed by the native build, without additional configuration. [WARNING] ====