It looks like you figured out, after your initial post, that you need to tell Gradle about your dependencies rather than try to execute tasks directly in a doFirst block, which is bad practice.
You wrote that your ant tasks are running after the build tasks and that you added this dependency:
ant_target_first.dependsOn build
This is exactly as would be expected because if ant_target_first depends on build, build would need to run first. You probably meant:
build.dependsOn ant_target_first
That would be the normal dependency if you’re just trying to tie your ant target into the Gradle lifecycle.