Q:

Gradle doFirst on ant target during execution

I'am trying to override a pre-built age old ant script. For some reasons, I cannot edit the ant file directly. 
-----------Psuedo of the gradle tasks--------
ant.importBuild antFileName

defaultTasks = ['greet']

task takeCare << {
println('Switch off security cam')
}

-----------Psuedo of the ant targets---------
<target name="greet">
        <echo>Be nice, say hello!</echo>
         <antcall target="tackle"/>
</target>

<target name="tackle">
        <echo>Brought him down!</echo>
</target>

What I want to achieve is to do a pre-check on gradle before calling ant target tackle. So my output looks like - 
Be nice, say hello!
Switch off security cam.
Brought him down!
How do I achieve this?

A:

Did you try this?
tackle.dependsOn takeCare

UPDATE
If you use dependsOn and run
gradle tackle 

you will get
:takeCare
Switch off security cam
:tackle
[ant:echo] Brought him down!

But if you use run greet, takeCare will not be executed, because you make an ant call directlly. So greet runs ant target and not gradle task.
You can try to change the tackle target in gradle.
ant.project.getTargets().find{it.value.name == "tackle"}.value

See java docs: Target

