I like that when defining a Task class in my Gradle plugin, putting an @Input annotation on the input parameters will validate that they are specified. Like this:
class MyTask extends DefaultTask {
@Input
String someProperty
@Input
@Optional
String someOtherProperty
...
}
What if I want to add some other kinds of custom validations around the property? Is there a good way to hook into what Gradle is already doing to validate additional things as well?
When I tried to write a unit test to make sure that the required inputs were specified, the task didn’t complain if I hadn’t specified required inputs. I was doing it like this:
Task testMyTask = project.tasks.create('testMyTask', MyTask) {
someOtherProperty = 'someValue'
}
// This will not complain, even though I failed to provide someProperty
testMyTask.doStuff() // where doStuff is a @TaskAction
Is there a good way to test whether the correct inputs are provided to the task?
Thanks