project.getTasksByName(“doesNotExist”)
Just so you know there’s
gradle.taskGraph.whenReady { ... }
Which is an event where you can inspect the TaskExecutionGraph and perform actions based on the tasks that are, or are not, in the task graph.
There’s also Task Rules where you can create dynamic/missing tasks based on name patterns.