Imported ant task depends on subproject build task is executed after build in a multproject build

Hi,
I am very much new in gradle. I am trying to migrate one existing ant build project into Gradle.

All my subprojects are applied with java plugin.
A few subprojects are imported with ant build files.

My project structure is like

rootProject
|—subProjectA
|-------build.gradle
|—subProjectB (ant xml imported subproject)
|-------build.gradle
|—subProjectC
|-------build.gradle
|—subProjectD (ant xml imported subproject)
|-------build.gradle
build.gradle
settings.gradle
gradle.properties
build_ant.xml ----(No target with name “build”)

I am calling “gradle build” from the root project.In subproject build files, I have written ant_target_first .dependsOn build

But the ant target are invoked after the build task (might be from parent).

Could you please suggest the best way to maintain the sequence of tasks in multi-build projects.

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.

You are correct, I actually meant

build.dependsOn ant_target_first only.

But my problem was, java compilation and jar creation was happening before the ant_target_first.

I tried serveral options and finally able to handle by changing the dependency by

compileJava.dependsOn ant_target_first

Is this the correct solution for the problem? Or Is there any better standard solution ?