How do I make sure code is executed after ALL instances of a particular task have completed successfully?

I’m setting it to run after uploadArchives, but I’m not sure where that is applied… it may not be applied to the root project at all.

In the test case I have, it is applied there, but that one gets called first, then the uploadArchives tasks for the subprojects, so only applying this at the root will make it get called after the first instance, not the last.

For final resolution, here’s what I did that finally made this work in my plugin. This method is called from the ‘apply’ in the plugin itself:

private void addMetadataTask() {
    if (!project.rootProject.getTasksByName('uploadBuildMetadata', false)) {
        LOGGER.debug('Adding uploadBuildMetadata task')
        def ubmTask = project.rootProject.tasks.create(name: 'uploadBuildMetadata', type: UploadBuildMetadata)

        project.rootProject.allprojects { proj ->
            proj.getTasksByName('uploadArchives', false).each {
                it.finalizedBy(ubmTask)
            }
        }
    }
}