How can I get a list of build targets in Ant?

Ant

Ant Problem Overview


My codebase has a long build.properties file written by someone else. I want to see the available built targets without having to search through the file manually. Does ant have a command for this - something like ant show-targets - that will make it list all the targets in the build file?

Ant Solutions


Solution 1 - Ant

The -p or -projecthelp option does exactly this, so you can just try:

ant -p build.xml

From ant's command line documentation:

> The -projecthelp option prints out a list of the build file's targets. Targets that include a description attribute are listed as "Main targets", those without a description are listed as "Other targets", then the "Default" target is listed ("Other targets" are only displayed if there are no main targets, or if Ant is invoked in -verbose or -debug mode).

Solution 2 - Ant

To get all the targets in the build file >ant -p -verbose

Solution 3 - Ant

The -p or -projecthelp option does exactly this, so you can do:

ant -p build.xml

You can make a target to invoke this like:

<target name="help">
    <java classname="org.apache.tools.ant.Main">
        <arg value="-projecthelp" />
        <arg value="-buildfile" />
        <arg value="${ant.file}" />
    </java>
</target>

which you can then set as the default, so just typing ant will list the available targets.

(Combining @Grodriguez' answer and @sschuberth's comment - I thought it was worth an answer by itself)

Solution 4 - Ant

You can check the list of target and default target in build.xml by the following command

ant -p built.xml

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShwetankaView Question on Stackoverflow
Solution 1 - AntGrodriguezView Answer on Stackoverflow
Solution 2 - AntShwetaView Answer on Stackoverflow
Solution 3 - AntrjmunroView Answer on Stackoverflow
Solution 4 - AntJainesh PatelView Answer on Stackoverflow