How do I call build-in tasks from my custom gradle task? I need to download some dependencies to the root of my project in eg. tmp. But I need to delete the tmp folder before (cleanup) if it exists:
public class FetchDeps extends DefaultTask
{
@TaskAction
void fetchDependencies() {
Project project = getProject();
// File projectDir = project.getProjectDir();
// Task byName = project.getTasks().getByName("Delete");
task deleteTmp(type: Delete) {
delete 'tmp' // if exists
}
task copyToTmp(type: Copy) {
into 'tmp'
from configurations.runtime
}
}
A task cannot call other tasks; it can only depend on them. In this particular case, you could also use the ‘project.delete’ and ‘project.copy’ methods.