Subant Task
Calls a given target for all defined sub-builds.
Apache Ant
 
Description

Calls a given target for all defined sub-builds. This is an extension of ant for bulk project execution. This task must no be used outside of a target if it invokes the same build file it is part of.

Use with directories

subant can be used with directory sets to execute a build from different directories. 2 different options are offered :

  • to run the same build file /somepath/otherpath/mybuild.xml with different base directories, use the genericantfile attribute
  • if you want to run directory1/mybuild.xml, directory2/mybuild.xml, ...., 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.
 
Parameters
Attribute Description Type Requirement
antfile Build file name, to use in conjunction with directories.
Defaults to "build.xml".
If genericantfile is set, this attribute is ignored.
String Optional
buildpath Set the buildpath to be used to find sub-projects. Path
buildpathref Buildpath to use, by reference. Reference
failonerror Sets whether to fail with a build exception on error, or go on. boolean
genericantfile Build file path, to use in conjunction with directories.
Use genericantfile, in order to run the same build file with different basedirs.
If this attribute is set, antfile is ignored.
File
inheritall Corresponds to <ant>'s inheritall attribute. boolean
inheritrefs Corresponds to <ant>'s inheritrefs attribute. boolean
output Corresponds to <ant>'s output attribute. String
target String
 
Parameters as nested elements
 
dirset (org.apache.tools.ant.types.DirSet)
Adds a directory set to the implicit build path.

Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!

 
filelist (org.apache.tools.ant.types.FileList)
Adds an ordered file list to the implicit build path.

Note that contrary to file and directory sets, file lists can reference non-existent files or directories!

 
fileset (org.apache.tools.ant.types.FileSet)
Adds a file set to the implicit build path.

Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!

 
property (org.apache.tools.ant.taskdefs.Property)
Corresponds to <ant>'s nested <property> element.
 
propertyset (org.apache.tools.ant.types.PropertySet)
Corresponds to <ant>'s nested <propertyset> element.
 
buildpath (org.apache.tools.ant.types.Path)
Creates a nested build path, and add it to the implicit build path.
 
buildpathelement (org.apache.tools.ant.types.Path.PathElement)
Creates a nested <buildpathelement>, and add it to the implicit build path.
 
Examples
        <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>
        

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.

          <subant target="">
             <propertyset>
                  <propertyref prefix="toplevel"/>
                  <mapper type="glob" from="foo*" to="bar*"/>
             </propertyset>
             <fileset dir="." includes="*/build.xml"/>
          </subant>
        

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

          <subant target="compile" genericantfile="/opt/project/build1.xml">
             <dirset dir="." includes="projects*"/>
          </subant>
        

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


Copyright © 2000-2003, Apache Software Foundation