Skip to content

Commit fabdf49

Browse files
committed
build: Apply jvmArgs also to JavaExec tasks
This allows to also run (not only test) the application without warnings form the IDE when using Java >= 17. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent d8ab5e7 commit fabdf49

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,30 @@ java {
118118
}
119119
}
120120

121+
val globalJvmArgs by extra {
122+
val javaVersion = JavaVersion.toVersion(javaLanguageVersion.toInt())
123+
124+
buildList {
125+
// See https://kotest.io/docs/next/extensions/system_extensions.html#system-environment.
126+
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
127+
add("--add-opens")
128+
add("java.base/java.io=ALL-UNNAMED")
129+
130+
add("--add-opens")
131+
add("java.base/java.lang=ALL-UNNAMED")
132+
133+
add("--add-opens")
134+
add("java.base/java.util=ALL-UNNAMED")
135+
136+
add("--add-opens")
137+
add("java.base/sun.nio.ch=ALL-UNNAMED")
138+
}
139+
}
140+
}
141+
121142
tasks.withType<JavaExec>().configureEach {
143+
jvmArgs = globalJvmArgs
144+
122145
val normalizedName = name.trimEnd { !it.isLetter() }.lowercase()
123146

124147
// Work around https://youtrack.jetbrains.com/issue/KTIJ-34755.
@@ -222,6 +245,8 @@ tasks.register<Jar>("javadocJar") {
222245
}
223246

224247
tasks.withType<Test>().configureEach {
248+
jvmArgs = globalJvmArgs
249+
225250
// Work-around for "--tests" only being able to include tests, see https://github.com/gradle/gradle/issues/6505.
226251
properties["tests.exclude"]?.also { excludes ->
227252
filter {
@@ -239,16 +264,6 @@ tasks.withType<Test>().configureEach {
239264
}
240265
}
241266

242-
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
243-
// See https://kotest.io/docs/next/extensions/system_extensions.html#system-environment.
244-
jvmArgs(
245-
"--add-opens", "java.base/java.io=ALL-UNNAMED",
246-
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
247-
"--add-opens", "java.base/java.util=ALL-UNNAMED",
248-
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED"
249-
)
250-
}
251-
252267
val testSystemProperties = mutableListOf("gradle.build.dir" to project.layout.buildDirectory.get().asFile.path)
253268

254269
listOf(

0 commit comments

Comments
 (0)