| <external> |
| <description> |
| <p> |
| Calls a given target for all defined sub-builds. |
| This is an extension |
| of ant for bulk project execution. |
| |
| <strong>This task must no be used outside of a |
| <code>target</code> if it invokes the same build file it is |
| part of.</strong> |
| </p> |
| <subsection name="Use with directories"> |
| <p> |
| subant can be used with directory sets to execute a build from different directories. |
| 2 different options are offered : |
| </p> |
| <ul> |
| <li> |
| to run the same build file <code>/somepath/otherpath/mybuild.xml</code> |
| with different base directories, use the genericantfile attribute |
| </li> |
| <li>if you want to run <code>directory1/mybuild.xml</code>, <code>directory2/mybuild.xml</code>, <code>....</code>, |
| use the antfile attribute. The subant task does not set the base directory for you in this case, because you can specify it in each build file. |
| </li> |
| </ul> |
| </subsection> |
| </description> |
| <section anchor="examples" name="Examples"> |
| <pre> |
| <project name="subant" default="subant1"> |
| <property name="build.dir" value="subant.build"/> |
| <target name="subant1"> |
| <subant target=""> |
| <property name="build.dir" value="subant1.build"/> |
| <property name="not.overloaded" value="not.overloaded"/> |
| <fileset dir="." includes="*/build.xml"/> |
| </subant> |
| </target> |
| </project> |
| </pre> |
| <p> |
| this snippet build file will run ant in each subdirectory of the project directory, |
| where a file called build.xml can be found. |
| The property build.dir will have the value subant1.build in the ant projects called by subant. |
| </p> |
| <pre> |
| <subant target=""> |
| <propertyset> |
| <propertyref prefix="toplevel"/> |
| <mapper type="glob" from="foo*" to="bar*"/> |
| </propertyset> |
| <fileset dir="." includes="*/build.xml"/> |
| </subant> |
| </pre> |
| <p> |
| this snippet build file will run ant in each subdirectory of the project directory, |
| where a file called build.xml can be found. |
| All properties whose name starts with "foo" are passed, their names are changed to start with "bar" instead |
| </p> |
| <pre> |
| <subant target="compile" genericantfile="/opt/project/build1.xml"> |
| <dirset dir="." includes="projects*"/> |
| </subant> |
| </pre> |
| <p> |
| assuming the subdirs of the project dir are called projects1, projects2, projects3 |
| this snippet will execute the compile target of /opt/project/build1.xml, |
| setting the basedir to projects1, projects2, projects3 |
| </p> |
| <p>Now a little more complex - but useful - scenario. Assume that we have |
| a directory structure like this:</p> |
| <pre> |
| root |
| | common.xml |
| | build.xml |
| | |
| +-- modules |
| +-- modA |
| | +-- src |
| +-- modB |
| +-- src |
| |
| <u><b>common.xml:</b></u><br/> |
| <project> |
| <property name="src.dir" value="src"/> |
| <property name="build.dir" value="build"/> |
| <property name="classes.dir" value="${build.dir}/classes"/> |
| |
| <target name="compile"> |
| <mkdir dir="${classes.dir}"/> |
| <javac srcdir="${src.dir}" destdir="${classes.dir}"/> |
| </target> |
| |
| <!-- more targets --> |
| </project> |
| |
| <u><b>build.xml:</b></u><br/> |
| <project> |
| |
| <macrodef name="iterate"> |
| <attribute name="target"/> |
| <sequential> |
| <subant target="@{target}"> |
| <fileset dir="modules" includes="*/build.xml"/> |
| </subant> |
| </sequential> |
| </macrodef> |
| |
| |
| <target name="compile"> |
| <iterate target="compile"/> |
| </target> |
| |
| <!-- more targets --> |
| </project> |
| |
| <u><b>modules/modA/build.xml:</b></u><br/> |
| <project name="modA"> |
| <import file="../../common.xml"/> |
| </project> |
| </pre> |
| |
| <p>This results in very small buildfiles in the modules, maintainable |
| buildfile (common.xml) and a clear project structure. Additionally |
| the root buildfile is capable to run the whole build over all |
| modules. |
| </p> |
| </section> |
| </external> |