1

I have multi-project build in gradle. Right now I am injecting tasks into each project in the following way

Closure clo = {task -> println "Run task"}
configure(subprojects.findAll {it.name == 'project1' || it.name == 'project2'})
{
   task helloTask << clo
}

Instead of iterating through all projects and selecting projects by their names, are there any better alternatives to all this? I couldn't get it to work using 'project' method, as the project method refuses to accept lists.

project([':project1', ':project2']) {
            task helloTask << clo
}
The Governor
  • 1,152
  • 1
  • 12
  • 28

1 Answers1

3

There isn't anything fundamentally better. I might write it as follows:

// use a suitable name that describes the subset of projects
def myProjects = [project(":project1"), project(":project2")]

configure(myProjects) {
    task helloTask << {
        println "Run task"
    }
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259