如何在Kotlin DSL的`run`上设置系统属性

时间:2018-12-22 19:50:32

标签: gradle kotlin gradle-kotlin-dsl

在Kotlin DSL中这等效于什么:

run {
    systemProperties["spring.output.ansi.enabled"] = "always"
}

我尝试过:

run {
    systemProperties("spring.output.ansi.enabled" to "always")
}

但是得到了:

* What went wrong: Script compilation error:

Line 37:     systemProperties(Pair("spring.output.ansi.enabled", "always"))
             ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
                 public inline fun JavaExec.systemProperties(vararg properties: Pair<String, Any?>): JavaExec defined in org.gradle.kotlin.dsl
                 public inline fun Test.systemProperties(vararg properties: Pair<String, Any?>): Test defined in org.gradle.kotlin.dsl
                 public inline fun JavaForkOptions.systemProperties(vararg properties: Pair<String, Any?>): JavaForkOptions defined in org.gradle.kotlin.dsl

2 个答案:

答案 0 :(得分:2)

我相信kotlin误将run块误认为其内置的run方法。 如果您指的是应用程序的插件,则可以使用以下命令配置其运行时属性

application {
   applicationDefaultJvmArgs = listOf("-Dspring.output.ansi.enabled=always")
}

在此处查看更多信息:

https://docs.gradle.org/current/userguide/application_plugin.html

答案 1 :(得分:1)

根据https://docs.gradle.org/current/userguide/kotlin_dsl.html#tasks

tasks {
    named<JavaExec>("run") {
        systemProperty("spring.output.ansi.enable", "always")
    }
}