I'm trying to pass arguments to my Kotlin Multiplatform desktop app.
I have this in my build.gradle.kts:
tasks.withType<JavaExec> { args = listOf("test") } This is my Main.kt file:
fun main(args: Array<String>) { println(args.toList()) // ... } When I run my app using ./gradlew run, this is printed:
[] The run task is of type JavaExec, why are the arguments not being passed then?
I also tried jvmArgs:
tasks.withType<JavaExec> { jvmArgs = listOf("-Dtest=true") } and this in my Main.kt:
fun main(args: Array<String>) { println(System.getProperty("test")) // ... } But again, when running ./gradlew run, the output is:
null UPDATE
I tried using specific name as suggested in the comments:
tasks.named<JavaExec>("run") { args = listOf("test") jvmArgs = listOf("-Dtest=true") } but I know get an error:
Task with name 'run' not found in project ':composeApp'. I also tried this:
tasks.withType<JavaExec> { println("Exec TASK: $name, $args, $jvmArgs") args = listOf("test") jvmArgs = listOf("-Dtest=true") } and this is the output:
Exec TASK: run, [], [] Exec TASK: runRelease, [], [] Exec TASK: desktopRun, [], [] So using tasks.withType<JavaExec> does find some tasks, but for some reason still doesn't set their arguments.