Gradle – run a task several times

Hi,
I’m new to Gradle, and currently working on gradually migrating a complex legacy Ant build to Gradle.

I’m looking for a simple way to run a task several times.

Why? - Our build produces 2 artifacts (let’s call them a.war & b.war) from the same set of sources. There are several differences between them, the main being some jars in a.war should be signed, and no jars in b.war should be signed.

I wanted to do it in a simple way by running the Ant build task twice with a parameter (& optimize later on), with something like this:

//… importing Ant etc.
task runner<<{

ant.properties['shouldSign’] = "true”
tasks.actualBuild.execute()
ant.properties['shouldSign’] = "false”
tasks.actualBuild.execute()
}

But Gradle doesn’t run a task twice…
I did try other ways, like use outputs.upToDateWhen{ false} on actualBuild and/or on a wrapper task, call it from a [true, false].each {} block.
Still, actualBuild would run only once.
(Yeah, I know I can simply modify the Ant file, but then what’s the point of using gradle?)
What am I doing wrong here?
How can I tell Gradle to run a task several times?

Thanks in advance,
DinaFK

Quite simply, you can’t, and this is by design. You’ll have to create two tasks, or in this case, Ant targets.

Thanks, I was going crazy trying to make this work.