I'm working with Gradle 8.12 and Java 22, and I'm encountering the following warning during build:
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader...
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning...
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
I understand this relates to Java's native access restrictions introduced in newer JDKs. I'm trying to silence the warning by setting:
--enable-native-access=ALL-UNNAMED
However, I'm unsure of the best way to add this JVM argument to Gradle. Should it go in gradle.properties, as an environment variable, or somewhere else? Also, is this the recommended way for builds using native-platform?
Any guidance on where exactly to configure this in a Gradle project (and whether this approach is safe/portable) would be appreciated!
To enable native access for all unnamed modules in IntelliJ IDEA, which is often necessary when working with newer JDK versions and certain libraries that utilize restricted methods, the --enable-native-access=ALL-UNNAMED
JVM option needs to be added to the project's or run configuration's JVM arguments.
Steps to add the JVM argument in IntelliJ IDEA:
Open Run/Debug Configurations:
Navigate to Run
> Edit Configurations...
in the IntelliJ IDEA menu.
Select the relevant configuration:
Choose the specific application or test configuration that requires native access.
Add JVM Options:
In the configuration settings, locate the "VM options" field (or "JVM options" depending on the configuration type).
Insert the argument:
Add --enable-native-access=ALL-UNNAMED
to this field. If other options are already present, separate them with spaces.
Apply and Run:
Click "Apply" and then "OK" to save the changes. The application or test can now be run with native access enabled for all unnamed modules.
Note: While --enable-native-access=ALL-UNNAMED
provides broad access, for more specific control, individual modules can be listed instead of ALL-UNNAMED
(e.g., --enable-native-access=M1,M2,...
). This option addresses warnings and potential errors related to restricted method access in newer Java versions.