I’m writing a plugin that creates a task for other tasks identified by the user within a configuration extension. I’m having difficulty with finding an approach that guarantees all tasks are available… at least within the project.tasks collection. I started off with a project.afterEvaluate closure but that’s not working in some cases. After some research it seems the another approach would be to switch to using project.tasks.whenTaskAdded but just wanted to see if there might be another approach.
Thanks for the example! The problem is that the maven-publish plugin is currently based on model rules which are executed after the evaluation phase. Until that is improved, you can use the all method on the task container:
project.afterEvaluate{ // so the user has a chance to configure 'findTasks'
project.tasks.all { task -> // so this is applied to all tasks, whether already created or not
if (project.findTasks.contains(task.name)) {
println task.name
}
}
}