views:

56

answers:

1

For various reasons that I won't go into (I promise it's necessary to do this with the current code base; I know it's goofy), I want to execute a target twice in the same build task.

For example, I want to execute the target foo, then bar, then foo again. This is a simplified version of what I already tried:

<target name="foo">
    ...
</target>

<target name="bar" depends="foo">
    ...
</target>

<target name="project" depends="foo,bar">
    ...
</target>

In this case when executing the project target, foo only ran once. I also tried getting rid of the depends attribute on the bar target and making the project's depends attribute "foo,bar,foo", but still the same result.

Is there a way to force a task to execute, even if it's already successfully completed? Or is there a better way to go about this?

+2  A: 

antcall will allow you to explicitly call a target.

I think that's a better solution than using the depends mechanism. As you've identified, this determines what has already run. Antcall instructs the target to run regardless of whether it's run before.

You can parameterise the call to customise what it does on each invocation.

Brian Agnew
I <3 SO for the 5 second answers. and at 7am no less.
Alex Beardsley
Midday here (in London) though :-)
Brian Agnew
ant is loosely based on make and make had the principle of dependencies between the targets. Thus once a target is run once you cannot get it to run again via dependencies.
Michael Wiles
You could probably write a custom executor (see Ant docs) to do what you want via target dependencies, but the default executor performs a topological sort that prevents your desired behavior.In the end it's probably simpler just to use antcall.