Skip to content

Commit 10dada3

Browse files
committed
Append $KSCRIPT_KOTLIN_OPTS to kotlin runtime opts.
1 parent 3c65e83 commit 10dada3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/kotlin/kscript/app/Kscript.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,16 @@ fun collectDependencies(scriptText: List<String>): List<String> {
230230
fun collectRuntimeOptions(scriptText: List<String>): String {
231231
val koptsPrefix = "//KOTLIN_OPTS "
232232

233+
// Append $KSCRIPT_KOTLIN_OPTS.
234+
// Overriding //KOTLIN_OPTS lines in the script relies on the JVM processing
235+
// arguments in order, which seems to be the case for Oracle, OpenJDK, and J9.
236+
val kscriptOpts = System.getenv()["KSCRIPT_KOTLIN_OPTS"]
237+
233238
return scriptText.
234239
filter { it.startsWith(koptsPrefix) }.
235-
map { it.replace(koptsPrefix, "").trim() }.
236-
joinToString(" ")
240+
map { it.replaceFirst(koptsPrefix, "").trim() }.
241+
joinToString(" ").
242+
plus( if ( kscriptOpts.isNullOrBlank() ) "" else " ${kscriptOpts}" )
237243
}
238244

239245

0 commit comments

Comments
 (0)