We have just upgraded our Java multi-project build from Gradle 2.2.1 to Gradle 2.4. Within one sub-project, we have a custom task that needs to depend on all ‘build’ tasks from all Java sub-projects. We use the following code to achieve this:
Unfortunately using “all” instead of “each” doesn’t compile for me - I get the following error:
No signature of method: java.util.TreeSet.all() is applicable for argument types:
…
Possible solutions: any(), last(), last(), add(java.lang.Object), add(java.lang.Object), any(groovy.lang.Closure)
However, we have since discovered that the following does seem to work:
customTask.dependsOn { project.parent.subprojects.findResults { it.tasks.findByName(“build”) } }
Thanks Rene. However, that last suggestion doesn’t work - the dependencies are still not created. The behaviour we’re looking for hinges on exactly when during the configuration phase the search for the “build” tasks occurs - it looks like that Gradle behaviour has changed between 2.2.1 and 2.4: is this deliberate and known, or a bug?
I’m assuming that the code in my second post above happens to delay the search for the tasks for “long enough” that they actually exist when it happens, but I’m still not clear on exactly why that is.
I have also came across this “issue” (I don’t knowi if it was an intended change). The workaround is to use subproject.tasks.names.findAll { it.equals('build') } instead of subproject.tasks.matching { task -> task.name.equals('build') }. Also, this is true for a couple of other tasks (or rules).