Define repeated task once

Hi,

I have a multi project build,
some of the sub-projects have the war task and some do not,
I want to add a task that depends on the war task (also on another one) cleans the webapp folder of a tomcat instance and copies the file there,
I also have a task like this but in a project where there’s only a single war,

what is the coolest way to handle this?
I tried using pluginManager and only have the task if war plugin is present but this only works after the task graph is ready,
also, I can’t declare dependency on the war task in the root project

I ended up using something similar to what is proposed in here:

def webProjects() {
    subprojects.findAll { subproject -> subproject.plugins.hasPlugin('war') }
 }

gradle.projectsEvaluated {
    configure(webProjects()) {
        //my config here
    }
}