jamesfredley commented on code in PR #15417:
URL: https://github.com/apache/grails-core/pull/15417#discussion_r2835662553
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -597,6 +601,74 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
+ /**
+ * Configures JVM arguments required for compatibility with Java 23+.
+ *
+ * <p>Java 24 introduced restrictions on native access ({@code JEP 472})
that cause
+ * warnings from libraries such as hawtjni (used by JLine) and Netty that
call
+ * {@code System.loadLibrary} or declare native methods. The
+ * {@code --enable-native-access=ALL-UNNAMED} flag suppresses these
warnings and
+ * will become mandatory in a future JDK release when the default changes
to deny.</p>
+ *
+ * <p>Java 23 began terminal deprecation of {@code sun.misc.Unsafe}
memory-access
+ * methods ({@code JEP 471/498}). Netty 4.1.x uses {@code
Unsafe.allocateMemory}
+ * for off-heap buffers. The {@code --sun-misc-unsafe-memory-access=allow}
flag
+ * suppresses the resulting warnings until Netty migrates to {@code
MemorySegment}
+ * APIs (Netty 4.2+).</p>
+ *
+ * <p>Both flags are only added when the target JVM version (from the
configured
+ * toolchain, or the JVM running Gradle if no toolchain is set) is high
enough to
+ * recognize them, avoiding {@code Unrecognized option} errors on older
JDKs.</p>
+ *
+ * @param project the Gradle project
+ * @see <a
href="https://github.com/apache/grails-core/issues/15216">#15216 - Java 25
native access warnings</a>
+ * @see <a
href="https://github.com/apache/grails-core/issues/15343">#15343 -
sun.misc.Unsafe deprecation warnings</a>
+ * @since 7.0.8
+ */
+ protected void configureJavaCompatibilityArgs(Project project) {
+ project.afterEvaluate {
Review Comment:
Removed. Replaced with `project.plugins.withId('java')` and moved the
version resolution into the `configureEach` callbacks so toolchain config is
read lazily after build script evaluation.
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -597,6 +601,74 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
+ /**
+ * Configures JVM arguments required for compatibility with Java 23+.
+ *
+ * <p>Java 24 introduced restrictions on native access ({@code JEP 472})
that cause
+ * warnings from libraries such as hawtjni (used by JLine) and Netty that
call
+ * {@code System.loadLibrary} or declare native methods. The
+ * {@code --enable-native-access=ALL-UNNAMED} flag suppresses these
warnings and
+ * will become mandatory in a future JDK release when the default changes
to deny.</p>
+ *
+ * <p>Java 23 began terminal deprecation of {@code sun.misc.Unsafe}
memory-access
+ * methods ({@code JEP 471/498}). Netty 4.1.x uses {@code
Unsafe.allocateMemory}
+ * for off-heap buffers. The {@code --sun-misc-unsafe-memory-access=allow}
flag
+ * suppresses the resulting warnings until Netty migrates to {@code
MemorySegment}
+ * APIs (Netty 4.2+).</p>
+ *
+ * <p>Both flags are only added when the target JVM version (from the
configured
+ * toolchain, or the JVM running Gradle if no toolchain is set) is high
enough to
+ * recognize them, avoiding {@code Unrecognized option} errors on older
JDKs.</p>
+ *
+ * @param project the Gradle project
+ * @see <a
href="https://github.com/apache/grails-core/issues/15216">#15216 - Java 25
native access warnings</a>
+ * @see <a
href="https://github.com/apache/grails-core/issues/15343">#15343 -
sun.misc.Unsafe deprecation warnings</a>
+ * @since 7.0.8
+ */
+ protected void configureJavaCompatibilityArgs(Project project) {
+ project.afterEvaluate {
+ int targetVersion = resolveTargetJavaVersion(project)
+
+ List<String> compatArgs = []
+
+ // JEP 472: Prepare to Restrict the Use of JNI - suppress native
access warnings
+ // from hawtjni (JLine 2.x) and Netty calling System.loadLibrary /
native methods
+ if (targetVersion >= 24) {
+ compatArgs.add('--enable-native-access=ALL-UNNAMED')
Review Comment:
Added `project.logger.info()` for each flag, e.g. `Grails: adding
--enable-native-access=ALL-UNNAMED to test for Java 25 compatibility`.
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -597,6 +601,74 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
+ /**
+ * Configures JVM arguments required for compatibility with Java 23+.
+ *
+ * <p>Java 24 introduced restrictions on native access ({@code JEP 472})
that cause
+ * warnings from libraries such as hawtjni (used by JLine) and Netty that
call
+ * {@code System.loadLibrary} or declare native methods. The
+ * {@code --enable-native-access=ALL-UNNAMED} flag suppresses these
warnings and
+ * will become mandatory in a future JDK release when the default changes
to deny.</p>
+ *
+ * <p>Java 23 began terminal deprecation of {@code sun.misc.Unsafe}
memory-access
+ * methods ({@code JEP 471/498}). Netty 4.1.x uses {@code
Unsafe.allocateMemory}
+ * for off-heap buffers. The {@code --sun-misc-unsafe-memory-access=allow}
flag
+ * suppresses the resulting warnings until Netty migrates to {@code
MemorySegment}
+ * APIs (Netty 4.2+).</p>
+ *
+ * <p>Both flags are only added when the target JVM version (from the
configured
+ * toolchain, or the JVM running Gradle if no toolchain is set) is high
enough to
+ * recognize them, avoiding {@code Unrecognized option} errors on older
JDKs.</p>
+ *
+ * @param project the Gradle project
+ * @see <a
href="https://github.com/apache/grails-core/issues/15216">#15216 - Java 25
native access warnings</a>
+ * @see <a
href="https://github.com/apache/grails-core/issues/15343">#15343 -
sun.misc.Unsafe deprecation warnings</a>
+ * @since 7.0.8
+ */
+ protected void configureJavaCompatibilityArgs(Project project) {
+ project.afterEvaluate {
+ int targetVersion = resolveTargetJavaVersion(project)
+
+ List<String> compatArgs = []
+
+ // JEP 472: Prepare to Restrict the Use of JNI - suppress native
access warnings
+ // from hawtjni (JLine 2.x) and Netty calling System.loadLibrary /
native methods
+ if (targetVersion >= 24) {
+ compatArgs.add('--enable-native-access=ALL-UNNAMED')
+ }
+
+ // JEP 471/498: sun.misc.Unsafe memory-access terminal deprecation
- suppress
+ // warnings from Netty's PlatformDependent0 using
Unsafe.allocateMemory
+ if (targetVersion >= 23) {
+ compatArgs.add('--sun-misc-unsafe-memory-access=allow')
Review Comment:
Done.
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -597,6 +601,74 @@ class GrailsGradlePlugin extends GroovyPlugin {
}
}
+ /**
+ * Configures JVM arguments required for compatibility with Java 23+.
+ *
+ * <p>Java 24 introduced restrictions on native access ({@code JEP 472})
that cause
+ * warnings from libraries such as hawtjni (used by JLine) and Netty that
call
+ * {@code System.loadLibrary} or declare native methods. The
+ * {@code --enable-native-access=ALL-UNNAMED} flag suppresses these
warnings and
+ * will become mandatory in a future JDK release when the default changes
to deny.</p>
+ *
+ * <p>Java 23 began terminal deprecation of {@code sun.misc.Unsafe}
memory-access
+ * methods ({@code JEP 471/498}). Netty 4.1.x uses {@code
Unsafe.allocateMemory}
+ * for off-heap buffers. The {@code --sun-misc-unsafe-memory-access=allow}
flag
+ * suppresses the resulting warnings until Netty migrates to {@code
MemorySegment}
+ * APIs (Netty 4.2+).</p>
+ *
+ * <p>Both flags are only added when the target JVM version (from the
configured
+ * toolchain, or the JVM running Gradle if no toolchain is set) is high
enough to
+ * recognize them, avoiding {@code Unrecognized option} errors on older
JDKs.</p>
+ *
+ * @param project the Gradle project
+ * @see <a
href="https://github.com/apache/grails-core/issues/15216">#15216 - Java 25
native access warnings</a>
+ * @see <a
href="https://github.com/apache/grails-core/issues/15343">#15343 -
sun.misc.Unsafe deprecation warnings</a>
+ * @since 7.0.8
+ */
+ protected void configureJavaCompatibilityArgs(Project project) {
+ project.afterEvaluate {
+ int targetVersion = resolveTargetJavaVersion(project)
+
+ List<String> compatArgs = []
+
+ // JEP 472: Prepare to Restrict the Use of JNI - suppress native
access warnings
+ // from hawtjni (JLine 2.x) and Netty calling System.loadLibrary /
native methods
+ if (targetVersion >= 24) {
+ compatArgs.add('--enable-native-access=ALL-UNNAMED')
+ }
+
+ // JEP 471/498: sun.misc.Unsafe memory-access terminal deprecation
- suppress
+ // warnings from Netty's PlatformDependent0 using
Unsafe.allocateMemory
+ if (targetVersion >= 23) {
+ compatArgs.add('--sun-misc-unsafe-memory-access=allow')
+ }
+
+ if (compatArgs) {
+ project.tasks.withType(Test).configureEach { Test task ->
+ task.jvmArgs(compatArgs)
+ }
+ project.tasks.withType(JavaExec).configureEach { JavaExec task
->
+ task.jvmArgs(compatArgs)
+ }
+ }
+ }
+ }
+
+ /**
+ * Resolves the Java version that forked tasks will use. Checks the
project's
+ * toolchain configuration first, falling back to the JVM running Gradle.
+ *
+ * @param project the Gradle project
+ * @return the major Java version number (e.g. 17, 21, 24, 25)
+ */
+ private int resolveTargetJavaVersion(Project project) {
+ JavaPluginExtension javaExtension =
project.extensions.findByType(JavaPluginExtension)
Review Comment:
Good call. Using `project.plugins.withId('java')` now, with the version
resolution inside `configureEach` so toolchain values are available.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]