0
votes

While troubleshooting a problem with apache-ivy, I want to call an ant target named -ivy-info defined in my build.xml. My -ivy-info target calls the ivy:info task and the ivy:buildnumber task and calculates the next revision number.

Problem is the ant command-line interprets the -ivy-info as a command-line option then fails with: Unknown argument: -ivy-info

One workaround I have found is to change the default target to -ivy-info via the first line of build.xml: <project name="my.project" default="-ivy-info"> and then run ant with no arguments, which works fine.

Other options are to rename the -ivy-info target so it does not start with a '-' character, or to create a new empty target with a name not starting with '-' and that includes -ivy-info as a dependency.

However I still want to know if there is any way that doesn't involve first editing build files?

1

1 Answers

1
votes

Anything starting with a "-" will be interpreted into an command-line argument, not a target. For example, there are usages like ant -f build-actual.xml or ant -Dproperty=value -- they are all Ant's command-line arguments. If you pass -ivy-info from command-line, of course, it is treated as an argument.

There's no way to run -ivy-info directly from command-line due to the argument parsing; and specifying it as the default target works because it is parsed by the xml parser, not command-line argument parser.

With this, when writing a build file, one can use "-" to prevent a target from being called directly from command-line (just like private methods in OO-languages). If the build file is not written by you, then the author doesn't want you to run it directly from command-line.

If you are sure that the target can be called directly from command-line, just rename it.