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

Viewed 389

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 Answers
Related