The task name starts with a hyphen "-".
<?xml version="1.0" encoding="UTF-8"?>
<project name="proj">
<target name="-task1">
<echo>Done!</echo>
</target>
</project>
How can I specify this task when running ant script from command line? This would not work:
ant -task1 -f test.xml
Some people start internal targets with dashes just to make sure users cannot run them from the command line. In fact, I make it a standard practice to have all internal targets start with
-
just for this reason.You can try the old double-dash trick. I don't have Ant installed on my current system, so I can't test it. Double dashes is a common Unix trick that most commands use to help end parameters when you have files and stuff that start with a dash. By the way, the tasks should be the last thing on your command line:
Worse comes to worse, you can simply define another target in your
build.xml
file that depends upon this target with the dash in it:Then you should be able to call
sneaky
:Enclose the task name in quotes.
Update: From Ant docs
From the ANT target doc
So, user cannot call the target with hyphen from commandline.
Tested on Windows Platform on 21 April 2016.