Usage Statements
Q:
In the
example from Chapter 3, you have an
all
target that builds everything. I
don’t want the build to do anything by default. Is
there a good way to pull this off?
It’s not the way, but a good
way to do this is to make a “usage
statement” target. Typically this target is called
help
and it simply echoes messages about the
common targets in the build. This behavior is similar to some Unix
(and some Windows) console programs. If you’re not
familiar with these console programs, they normally do nothing if
called from the command line with no arguments. Instead, they display
a message, starting with the text
“Usage” that shows the various
command-line arguments you can use with the program. Our
help
target does the same thing, as the following
example shows:
<project name="usage_example" default="help" basedir="."> <!-- some properties --> <!-- some paths --> <target name="build-lib"/> <target name="build-app"/> <target name="deploy-app"/> <target name="makedoc"/> <target name="help"> <echo message="Build the usage_example project"/> <echo message="Usage: ant [ant options] <target1> \ [target2 | target3 | ... ]"/> <echo message=""/> <echo message=" build-lib - build just the project's library"/> <echo message=" build-app - build the library and \ the application"/> <echo message=" deploy-app - ready the \ application for deployment"/> <echo message=" makedoc - generate all the \ documentation for the project"/> <echo message=" -projecthelp - (An Ant option) Display ...
Get Ant: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.