Is it not allowed to call the B task in the A task in Gradle?

task testHaHa {
    doFirst {
        if (true) {
            A()
//            tasks.named("A").get().execute()
        }else {
//            ...
        }
    }
}

task A {
    doFirst {
        println "A exec"
    }

}

I need to determine the A task, or other tasks when performing the TESTHAHA task according to the logic judgment, but I find that it cannot be implemented.
It always reports an error. How should I modify it?
I hope that A task is a task rather than a method, because the task seems to be more in line with Gradle’s design concept.

Yes, you are correct.
You cannot “call” one task from another task.
You can only model dependencies between tasks.