与Gradle相关的任务不会将命令行选项传递给父任务 [英] Gradle dependent task doesn't pass command line options to parent task
问题描述
我正在编写一个自定义Gradle任务,该任务接受命令行中的选项。该部分按预期工作。导致我出现问题的是,调用依赖任务时,命令行选项被拒绝,因为它与依赖任务无关。以下是一个演示问题的示例:
I'm writing a custom Gradle task that accepts an option from the command line. That part works as expected. What's causing me issues is that calling a dependent task, the command line option is rejected because it's not relevant to the dependent task. Here's a sample that demonstrates the issue:
class CustomTask extends DefaultTask {
@Option(option = "stuff", description = "Custom task stuff")
String stuff
@TaskAction
void action() {
if (this.stuff?.trim()) {
println this.stuff
}
else {
throw new InvalidUserDataException("No stuff!")
}
}
}
task custom(type: CustomTask)
task depends(dependsOn: 'custom')
以下是路径:
-
渐变自定义
正确引发异常 -
gradle自定义--stuff = mystuff
发出mystuff
当任务运行时。 -
等级取决于
正确引发相同的异常 -
等级取决于--stuff = mystuff
失败,并显示未知命令行选项'--stuff'
gradle custom
correctly throws an exceptiongradle custom --stuff=mystuff
emitsmystuff
when the task runs.gradle depends
correctly throws the same exceptiongradle depends --stuff=mystuff
fails withUnknown command-line option '--stuff'
如何使命令行选项-东西
传递给自定义
任务,何时调用 depends
任务?
How do I make the command line option --stuff
pass through to the custom
task when calling the depends
task?
推荐答案
不幸的是,这是选项 https:// docs的已记录限制之一。 gradle.org/current/userguide/custom_tasks.html#limitations
您可以改用build属性,并使用传递它们-Pstuff =某物
You could use build properties instead, and pass them in with -Pstuff=something
这篇关于与Gradle相关的任务不会将命令行选项传递给父任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!