How to get a list of all subprojects containing a specify task at configuration time?

Hello,

  1. I have a multi project scenario, my root project contains something like this inside build.gradle:

    subprojects{
    task myTask {
    … do something
    }
    }

  2. I have then several sub projects (:a,:b,:c,:d). Some of these apply the war plugin using:

    plugins {
    id ‘war’
    }

  3. Inside one of the subprojects( :b) that also applies the plugin ‘war’ I want obtain some informations about the other subprojects. I want to create list of all suproject that have a task (i.e ‘war’) available. I have tried the following in build.gradle of sub project :b without success:

println rootProject.subprojects.tasks.each{it.findByPath('war')}

This returns:

[[ task ':a:assemble', task ':a:buildDepends' .....]

I would expect

[:a:war, :b:war,...]

Any idea?

The following should do:

subprojects {
    apply plugin: 'war'
}

task subprojectApplyingWarPlugin {
    doLast {
        println subprojects.findAll { subproject -> subproject.plugins.hasPlugin('war') }
    }
}

Here we are actually asking whether the War plugin has been applied rather than if the war task exists.

Thanks, that indeed can give me the list at it’s ok too to base it on the plug-in presence. But I need to do it at configuration time and when I try just the following in the build.gradle of a subproject:

println rootProject.subprojects.findAll { subproject -> subproject.plugins.hasPlugin('war') }

it only return the subprojects already configured, not those still to be configured.
I basically need to tell that the task “X” that is present in most subprojects, should run last in project “last” as long as this project is included in the build.

Something like this should do:

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

gradle.projectsEvaluated {
    configure(webProjects()) {
        ...
    }
}

Thanks!,

that sounds like something I can use. Let me try and I will get back