How to add TaskExecutionGraphListener in root project as the LAST listener

I have various places where my sub-projects call gradle.taskGraph.whenReady. I need to add a another of these listeners in the root project and make sure it gets called as the LAST listener. How can I achieve this?

Thanks for any ideas.

You could use Project.evaluationDependsOn(path) to make the rest of the parent script evaluate after the child scripts. But first I’d try to find a solution that doesn’t require a particular ordering of listeners.

Hi Peter

Thanks for your answer.

I cannot get around the order, I believe. Use case: all child-projects can modify their POM, make some dependencies optional, remove some dependencies, etc. When all this is done, I want some code in the root project to go over the pom and re-order the items according to multiple criteria (name. optional or not, etc.). This can only be done being the last listener.


You could offer a method that children use to do the post-processing themselves. Not fully transparent but maybe still preferable to worrying about the order of listeners.

Another approach is to do the post-processing in a doFirst {} of the upload task (which you could add from the parent build script).

If you want to stick to the task graph listener approach (why this listener by the way?), Project.evaluationDependsOn(path) is probably your best bet.