下面是Groovy的一个例子,它准确地表达了我想要实现的目标:
Command line
:
./gradlew jib -PmyArg=hello
build.gradle.kts
task myTask {
doFirst {
println myArg
... do what you want
}
}
此示例的来源为here - option 3。
如何在Kotlin DSL中读取通过和读取myArg
值?
答案 0 :(得分:1)
一段时间后找到答案:
build.gradle.kts
val myArg: String by project // Command line argument is always a part of project
task("myTask") {
doFirst {
if (project.hasProperty("myArg")) {
println(myArg)
}
}
}
Command line
:
gradle myTask -PmyArg=foo
Output
:
$ gradle myTask -PmyArg=foo
> Task :myTask
foo
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
相关链接: