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:
gradle customcorrectly throws an exceptiongradle custom --stuff=mystuffemitsmystuffwhen the task runs.gradle dependscorrectly throws the same exceptiongradle depends --stuff=mystufffails withUnknown command-line option '--stuff'
How do I make the command line option --stuff pass through to the custom task when calling the depends task?