如何将所有系统属性传递给 gradle kotlin dsl 中的测试任务?

How to pass all system properties to test task in gradle kotlin dsl?

如何将此 gradle groovy 片段转换为 gradle kotlin dsl 而不是非常冗长?

test {
    systemProperties System.getProperties() 
}

我发现的最不冗长的方式是:

tasks.test {
    systemProperties(System.getProperties().mapKeys { it.key as String })
}

Test#systemProperties expects a Map<String, Object> but System#getProperties returns 一个 java.util.Properties 对象所以仍然需要转换。

我最终得到了这个...

tasks.named<Test>("test") {
    systemProperties System.getProperties() as Map<String, Any>
}

这对我有用...

test { systemProperties(System.getProperties().map { it.key.toString() to it.value }.toMap()) }