与Gradle相关的任务不会将命令行选项传递给父任务 [英] Gradle dependent task doesn't pass command line options to parent task

查看:74
本文介绍了与Gradle相关的任务不会将命令行选项传递给父任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个自定义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')

以下是路径:


  1. 渐​​变自定义正确引发异常

  2. gradle自定义--stuff = mystuff 发出 mystuff 当任务运行时。

  3. 等级取决于正确引发相同的异常

  4. 等级取决于--stuff = mystuff 失败,并显示未知命令行选项'--stuff'

  1. gradle custom correctly throws an exception
  2. gradle custom --stuff=mystuff emits mystuff when the task runs.
  3. gradle depends correctly throws the same exception
  4. gradle depends --stuff=mystuff fails with Unknown 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆