The Governor
The Governor

Reputation: 1192

Project specific Configuration injection in gradle

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
}

Upvotes: 1

Views: 565

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

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"
    }
}

Upvotes: 3

Related Questions