Custom Task gets executed before the dependencies are completed

I have a java sub-project which has some other projects as dependencies.

The sub-project also has a custom task which is dependent on some more custom tasks. All of these custom tasks are defined in the build.gradle of the sub-project.

The custom tasks needs to be called when I call the project “build” task from the top level build.gradle with “gradle build” command. To achieve that I have added “project.build.dependsOn customTaskName” in the sub-project build.gradle.

Now the problem is when I am calling the project build task from the top level build.gradle, the custom task in sub-project is getting executed even before the dependencies of the sub-project, though I have mentioned the dependencies inside a dependencies closure in the sub-project build.gradle.

Any idea how I can execute the sub-project’s custom task as part of project “build” task in a proper sequence after the dependencies of the sub-project ?

You’ll have to establish the necessary task dependencies. Sometimes Gradle can infer task dependencies automatically, but I’d have to know more about your concrete situation.