Execute a set of build tasks at once

Gradle automatically creates several build tasks based on platforms, build types, etc. Say I have a project Foo, and the generated build tasks are:

  1. debugFoo32
  2. releaseFoo32
  3. debugFoo64
  4. releaseFoo64

I want a task allFoo64, which executes both debugFoo64 and releaseFoo64.

This is my attempt:

task buildAllExecutables64 {
    dependsOn project.binaries.withType(NativeLibrary).findAll { it.targetPlatform.name.contains("64") }

    //Shows result of find all
    println "findAll = " + 
         project.binaries.withType(NativeLibrary).findAll{it.targetPlatform.name.contains("64") }

But the output of findAll is empty. So I changed the phase in which the task is executed, changing its definition in:

task buildAllExecutables64 << {...}

This however causes this exception to be thrown:

Execution failed for task ‘:buildAllExecutables64’.

Cannot call Task.mustRunAfter(Object…) on task ‘:buildAllExecutables64’ after task has started execution. Check the configuration of task ‘:buildAllExecutables64’ as you may have misused ‘<<’ at task declaration.

Any ideas? Sorry, but I’m a Gradle newbie

you want to use dependsOn.
Basically your allFoo64 task is empty, and only depends on the two other tasks

tasks.create(‘allFoo64’).dependsOn ‘debugFoo64’,‘releaseFoo64’

or something like that

Perfect, it works!

Thank you very much,

You should also be able to do something like this:

task buildAllExecutables64 {
    dependsOn binaries.withType(NativeLibrary).matching { it.targetPlatform.name.contains("64") }

findAll() immediately evaluates the collection, while matching() is lazy. You probably want to filter on buildable too.

There are a couple of examples of this in the samples that come with Gradle: https://github.com/gradle/gradle/search?utf8=✓&q=matching+path%3Asubprojects%2Fdocs%2Fsrc%2Fsamples%2Fnative-binaries%2F&type=Code