Hi, I’d like to create a dynamic gradle task that has custom inputs and outputs.
For example if i create dynamic task as follows:
def taskBody = {
println "I'm task body"
}
Task dynamicTask = task "$taskName" << taskBody
dynamicTask.doFirst {
inputs.dir(new File(projectDir, "src")) // FIXME
outputs.dir(new File(projectDir, "target")) // FIXME
println 'doFirst '
return this
}
then custom inputs and outputs are not taken into consideration and following warning is shown: “Calling TaskInputs.dir(Object) after task execution has started has been deprecated and is scheduled to be removed in Gradle 2.0.” How can i do it properly? -------------------------------------------- Here are some thoughts that didn’t quite do the trick either:
One thing i thought about was to create a custom Task, let’s say:
class MyTask extends DefaultTask {
private MyTask (String someArg) {
// do smth with the arg
}
public Task doFirst(Action<? super Task> action) {
Task task = super.doFirst(action);
inputs.dir(new File(projectDir, "src"))
outputs.dir(new File(projectDir, "target"))
println 'doFirst '
return task
}
@TaskAction
def executeMyTaskBody() {
println "I'm task body"
}
}
But i can’t figure out how to instanciate that custom task
new MyTask(someArg) //Task of type 'MyTask' has been instantiated directly which is not supported.
// (probably TaskFactory won't help me either if i want to set custom inputs?)
and add the instance to the project.
Probably i’m just unable to google for smth really trivial, but i don’t have almost any experience with Gradle.
Tnx in advance, Ats