How to enable -Dkotlinx.coroutines.debug in IntelliJ IDEA? I have the following code from coroutines documentation:
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
fun main() = runBlocking<Unit> {
val a = async {
log("I'm computing a piece of the answer")
6
}
val b = async {
log("I'm computing another piece of the answer")
7
}
log("The answer is ${a.await() * b.await()}")
}
I was trying to add this option in "Run -> Edit configuration":
but after this I expected to see the following output (as docs say):
[main @coroutine#2] I'm computing a piece of the answer
[main @coroutine#3] I'm computing another piece of the answer
[main @coroutine#1] The answer is 42
but actually I see plain usual output:
[main] I'm computing a piece of the answer
[main] I'm computing another piece of the answer
[main] The answer is 42
So how to enable this JVM option?
You are configuring and running a Gradle run
target. Means you configure Gradle with this parameter. But Gradle does not use this parameter to start your Kotlin example.
You should run and configure a Kotlin target. You see it as the second node of the left side in your screenshot.
Or if you really want to use Gradle you can pass the system properties through to the JavaVM:
run {
systemProperties System.properties
}