How to get the target as a property in Ant?

Perhaps one of those really scary beginner questions is when the guide tells you everything, but anyway, take this line below:

ant -Dfoo=bar buildme 

in my build script, what is the property that contains "buildme"?

+4
source share
3 answers

Not sure if I understand your question, but "buildme" is the goal to execute, not the property.

 ant [options] [target [target2 [target3] ...]] 

You β€œpick” it, creating the corresponding goal:

 <target name="buildme"> <!-- tasks that will execute here --> </target> 

As for the foo property, you select it with $ {foo}.

0
source

A list of assigned goals is available in the property.

 ant.project.invoked-targets 

If the default target is set, then this will be the called target. If one or more targets are specified on the command line, they are displayed separated by commas in the property. Note that the property is only set after execution moves to the target β€” if you try to read the property outside of any target, it will be canceled.

So, if the project has a default goal of "zero":

 $ ant one two # ant.project.invoked-targets is set to: one,two 

and

 $ ant # ant.project.invoked-targets is set to (default): zero 
+3
source

It seems that ant.project.invoked-targets not available in ant 1.7.1

+1
source

All Articles