如何在IntelliJ IDEA中启用-Dkotlinx.coroutines.debug?

4
如何在IntelliJ IDEA中启用-Dkotlinx.coroutines.debug? 我有来自协程文档的以下代码:
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()}")    
}

我尝试在“运行 -> 编辑配置”中添加此选项:

enter image description here

但是根据文档,我期望看到以下输出:
[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

但实际上,我看到的只是普通的输出:
[main] I'm computing a piece of the answer
[main] I'm computing another piece of the answer
[main] The answer is 42

那么如何启用这个JVM选项?
1个回答

3
您正在配置和运行一个Gradle运行目标。这意味着您使用此参数配置Gradle。但是Gradle不会使用此参数来启动您的Kotlin示例。
您应该运行和配置一个Kotlin目标。您可以在屏幕截图的左侧看到它作为第二个节点。
或者,如果您真的想使用Gradle,您可以通过JavaVM传递系统属性。
run {
    systemProperties System.properties
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接