Gradle dependent task doesn't pass command line options to parent task

左心房为你撑大大i 提交于 2020-01-06 11:44:37

问题


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')

Here are the paths:

  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'

How do I make the command line option --stuff pass through to the custom task when calling the depends task?


回答1:


Unfortunately, that's one of the documented limitations of options https://docs.gradle.org/current/userguide/custom_tasks.html#limitations

You could use build properties instead, and pass them in with -Pstuff=something



来源:https://stackoverflow.com/questions/52171801/gradle-dependent-task-doesnt-pass-command-line-options-to-parent-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!