如何将命令行参数传递给Gradle Kotlin DSL [英] How to pass command line argument to Gradle Kotlin DSL
本文介绍了如何将命令行参数传递给Gradle Kotlin DSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是Groovy的一个例子,它准确地表达了我想要实现的目标:
Here's an example from Groovy that represents exactly what I would like to achieve:
Command line
:
./gradlew jib -PmyArg=hello
build.gradle.kts
task myTask {
doFirst {
println myArg
... do what you want
}
}
此示例的来源为此处-选项3 .
如何在Kotlin DSL中读取pass并读取myArg
值?
How can I read pass and read myArg
value in Kotlin DSL ?
推荐答案
一段时间后找到答案:
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
相关链接:
- How to pass arguments from command line to gradle
- How to pass parameters or arguments into a gradle task
- Gradle task check if property is defined
这篇关于如何将命令行参数传递给Gradle Kotlin DSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文