9191}
9292
9393
94+ // Collect extra arguments for the JVM in the test task
95+ ext. jythonTestJvmArgs = []
96+
97+ // Explicitly provided in a property
98+ def extraJythonTestJavaOpts = findProperty(' jython.test.java.opts' )
99+ if (extraJythonTestJavaOpts) {
100+ ext. jythonTestJvmArgs. addAll(
101+ extraJythonTestJavaOpts. toString(). trim(). split(/ \s +/ ). findAll { it })
102+ }
103+
104+ // JVM aguments necessitated by later versions of Java
105+ // FIXME: Gradle 7.4.2 returns at most 21 here even on Java 25.
106+ // (Fix by updating Gradle: the code is correct and the warnings harmless.)
107+ def currentJavaMajor = JavaVersion . current(). majorVersion as int
108+ if (currentJavaMajor >= 9 ) {
109+ ext. jythonTestJvmArgs. addAll([
110+ ' --add-opens=java.base/java.io=ALL-UNNAMED' ,
111+ ' --add-opens=java.base/sun.nio.ch=ALL-UNNAMED'
112+ ])
113+ }
114+ if (currentJavaMajor >= 25 ) {
115+ ext. jythonTestJvmArgs. addAll([
116+ ' --enable-native-access=ALL-UNNAMED' ,
117+ ' --sun-misc-unsafe-memory-access=allow'
118+ ])
119+ }
120+
121+
94122repositories {
95123 // Jython is distributed through Maven Central. Get our dependencies there too.
96124 mavenCentral()
@@ -651,7 +679,8 @@ jar {
651679 ' Main-Class' : ' org.python.util.jython' ,
652680 ' Built-By' : ' build.gradle' ,
653681 ' Automatic-Module-Name' : ' org.python.jython2' ,
654- ' Enable-Native-Access' : ' ALL-UNNAMED'
682+ ' Enable-Native-Access' : ' ALL-UNNAMED' ,
683+ ' Add-Opens' : ' java.base/java.io java.base/sun.nio.ch'
655684 ])
656685
657686 attributes( [ // Build-Info section
@@ -684,6 +713,8 @@ task testJar(type: Jar) {
684713 attributes ([
685714 // 'Main-Class': 'org.python.util.jython',
686715 ' Built-By' : ' build.gradle' ,
716+ ' Enable-Native-Access' : ' ALL-UNNAMED' ,
717+ ' Add-Opens' : ' java.base/java.io java.base/sun.nio.ch'
687718 ])
688719
689720 attributes( [ // Build-Info section
@@ -864,6 +895,7 @@ test {
864895 systemProperty ' python.cachedir' , " ${ project.buildDir} /cachedir"
865896 // Logging level: default is message=INFO
866897 // systemProperty 'python.verbose', 'CONFIG'
898+ jvmArgs project. ext. jythonTestJvmArgs
867899
868900 include ' **/*Test*'
869901
@@ -890,7 +922,10 @@ test {
890922 exclude ' org/python/util/InterpreterTest.class'
891923
892924 doFirst {
893- println " systemProperties = $systemProperties "
925+ println " systemProperties = $systemProperties "
926+ println " JavaVersion = ${ JavaVersion.current()} "
927+ println " jythonTestJvmArgs = ${ project.ext.jythonTestJvmArgs} "
928+ println " allJvmArgs = ${ allJvmArgs} "
894929 }
895930
896931}
0 commit comments