Wednesday, October 1, 2008

Understand depends in Ant

In a chain of dependencies, each target gets executed only ONCE.

For example:
<target name="echo1">
<echo>1</echo>
</target>

<target name="echo2">
<echo>2</echo>
</target>

<target name="echo3">
<echo>3</echo>
</target>

<target name="test1" depends="echo1, echo2"/>
<target name="test2" depends="echo1, echo3"/>

<target name="duplicate" depends="test1,test2" />


Run "ant duplicate", the result will be
C:\temp>ant duplicate
Buildfile: build.xml

echo1:
[echo] 1

echo2:
[echo] 2

test1:

echo3:
[echo] 3

test2:

duplicate:

BUILD SUCCESSFUL
Total time: 0 seconds


But if you do want to execute echo1 twice, how to do it?
<target name="test11">
<antcall target="echo1"/>
<antcall target="echo2"/>
</target>

<target name="test22">
<antcall target="echo1"/>
<antcall target="echo3"/>
</target>

<target name="duplicateAgain" depends="test11,test22" />


Run "ant duplicateAgain" and the result will be
C:\temp>ant duplicateAgain
Buildfile: build.xml

test11:

echo1:
[echo] 1

echo2:
[echo] 2

test22:

echo1:
[echo] 1

echo3:
[echo] 3

duplicateAgain:

BUILD SUCCESSFUL
Total time: 0 seconds

No comments:

Post a Comment