I would like to ask you for help. I somehow don’t understand, how to leverage Gradle’s Delete task in execution phase.
task T1(dependsOn: T2)
<< {
// some behaviour
}
task T2(type: Delete) << {
delete 'myTestFile.txt'
// since this is in execution phase, it won't work as expected
}
But I don’t want to do this:
task T2(type: Delete) {
// no matter what task is executed, this is executed always :-(((((
// I need it to bind to T1 task, which is run in execution (if user invokes it)
}
Because T2 is a Delete task, the ‘delete’ method in the configuration closure we have there means something different to what it would if it were not a Delete task.
In this case, you are specifying what should be deleted when the task runs. That is, you are configuring the delete task. If the task was not a delete task, the delete method would actually be ‘Project.delete()’ which deletes the file right at that time.