Hi,
the docs say about configuration avoidance (Task Configuration Avoidance) that I can call dependsOn
on a TaskProvider
without configuring the task.
Calling Provider.get() or looking up a task by name with TaskCollection.getByName(java.lang.String) will cause the task to be created and configured. Methods like Task.dependsOn(java.lang.Object…) and ConfigurableFileCollection.builtBy(java.lang.Object…) work with TaskProvider in the same way as Task, so you do not need to unwrap a
Provider
for explicit dependencies to continue to work.
However, this does not work. The API does not list dependsOn
as a method on TaskProvider
(TaskProvider (Gradle API 8.4)). Unsurprisingly, this Java code snippet
TaskProvider<DefaultTask> myTask = this.project.getTasks().register("myTask", DefaultTask.class, task -> {
task.setGroup("Test");
});
myTask.dependsOn(this.project.getTasks().getByName("build"));
results in
cannot find symbol
myTask.dependsOn(this.project.getTasks().getByName("build"));
^
symbol: method dependsOn(Task)
location: variable myTask of type TaskProvider<DefaultTask>
Am I misinterpreting the configuration avoidance manual?