Inside a gradle Task object you can say something like: ant.taskdef(...)
According to the gradle specification on the Task class its property “ant” is of type “AntBuilder”.
However the gradle specifiaction on “Antbuilder” does not mention a method called “taskdef”. Why then can I say “ant.taskdef”?
Hm if I say println(ant.getClass()), I get “org.gradle.api.internal.project.DefaultAntBuilder”.
However upon inspecting that classes code, neither it nor its superclasses have a method called “taskdef”.
Where does that “taskdef” method come from or if it is not a method, what is it technically?
You say it is provided by the Groovy language. But I cannot find a description of this kind of enhancement in the Groovy documentation.
It is effectively dynamically created at runtime. When you call ant.taskDef() Groovy is intercepting this method and instead of trying to execute some method named taskDef() it is building an internal XML like structure (just like an Ant build.xml) file. It then uses this data model to delegate to Ant itself.