How to declare a task to be run once after ALL multiproject task builds have finished

I want to declare a task that will be run once after all multiproject tasks finish.

(and not run after EACH task).

In other words, printArtifactDependencies should run ONCE and only once in the example below.

I think its actually sufficient to simply run once before gradle exits.

Any advice is appreciated.

project.task(‘gatherArtifactDependencies’) {

group ‘RUP’

doLast {

project.allprojects.each { proj ->

proj.configurations.each { conf ->

conf.allDependencies.findAll { && == project.getProperty(CONSUMING_GROUP_KEY) }.each { dep ->

RupBasePlugin.dependencyList << new Dependency( )






project.task(‘printArtifactDependencies’) {

group ‘RUP’

doLast {

logger.lifecycle "Final size is ${dependencyList.size()} "



// does not work. I want this task to run after ALL gatherArtifactDependencies tasks for all projects have finished


Easiest solution is to put such logic into ‘gradle.buildFinished {}’, rather than into a task.

Sorry, I think my wording was not clear above.

I want the logger.lifecycle to run only when printArtifactDependencies task is executed and only after gatherArtifactDependencies has already run.

Using gradle.buildFinished {} would always run on any build (if I understand it correctly).

I should also mention this logic is going inside a custom plugin.

I don’t understand. I can only spot a single ‘gatherArtifactDependencies’ task that iterates over all projects.


gatherArtifactDependencies task iterates over all projects (and accumulates all dependencies into a list).

Once the above completes I want to print out the size of the list and perform other processing on the list.

The overall goal is simply to gather all the dependencies across all subprojects so I can work with the list in memory.

Although gatherArtifactDependencies is declared once, it executes once PER PROJECT.

Which was a surprise.

So if you think I am headed down a wrong path, I am happy to reverse course and rethink my approach.

Thanks very much

I don’t see why ‘project.printArtifactDependencies.dependsOn(‘gatherArtifactDependencies’)’ wouldn’t work then (as long as you run ‘gradle printArtifactDependencies’). You could also do the printing right inside ‘gatherArtifactDependencies’.

I am not sure either.

I will say that the same code works inside build.gradle.

But not from our custom plugin.

Thank you, Peter.

I will have to re-think my strategy.