## Ant

### Description

Runs Ant on a supplied buildfile. This can be used to build subprojects.

When the antfile attribute is omitted, the file "build.xml" in the supplied directory (dir attribute) is used.

If no target attribute is supplied, the default target of the new project is used.

By default, all of the properties of the current project will be available in the new project. Alternatively, you can set the inheritAll attribute to `false` and only "user" properties (i.e., those passed on the command-line) will be passed to the new project. In either case, the set of properties passed to the new project will override the properties that are set in the new project (See also the property task).

You can also set properties in the new project from the old project by using nested property tags. These properties are always passed regardless of the setting of inheritAll. This allows you to parameterize your subprojects.

References to data types can also be passed to the new project, but by default they are not. If you set the inheritrefs attribute to true, all references will be copied, but they will not override references defined in the new project.

Nested <reference> elements can also be used to copy references from the calling project to the new project, optionally under a different id. References taken from nested elements will override existing references in the new project.

### Parameters

Attribute | Description | Required
antfile | the buildfile to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given. | No
dir | the directory to use as a basedir for the new Ant project. Defaults to the current project's basedir, unless inheritall has been set to false, in which case it doesn't have a default value. This will override the basedir setting of the called project. | No
target | the target of the new Ant project that should be executed. Defaults to the new project's default target. | No
output | Filename to write the ant output to. This is relative to the value of the dir attribute if it has been set or to the base directory of the current project otherwise. | No
inheritAll | If `true`, pass all properties to the new Ant project. Defaults to `true`. | No
inheritRefs | If `true`, pass all references to the new Ant project. Defaults to `false`. | No

### Parameters specified as nested elements

#### property

See the description of the property task. Note that the `refid` attribute points to a reference in the calling project, not in the new one.

#### reference

Used to chose references that shall be copied into the new project, optionally changing their id.

Attribute | Description | Required
refid | The id of the reference in the calling project. | Yes
torefid | The id of the reference in the new project. | No, defaults to the value of refid.

### Basedir of the new project

The basedir value of the new project is affected by the two attributes dir and inheritall, see the following table for details:

dir attribute | inheritAll attribute | new project's basedir
value provided | true | value of dir attribute
value provided | false | value of dir attribute
omitted | true | basedir of calling project (the one whose build file contains the <ant> task).
omitted | false | basedir attribute of the <project> element of the new project

### Examples

      <ant antfile="subproject/subbuild.xml" dir="subproject" target="compile"/>

      <ant dir="subproject"/>

      <ant antfile="subproject/property_based_subbuild.xml">
        <property name="param1" value="version 1.x"/>
        <property file="config/subproject/default.properties"/>
      </ant>

      <ant inheritAll="false" antfile="subproject/subbuild.xml">
        <property name="output.type" value="html"/>
      </ant>

The build file of the calling project defines some `<path>` elements like this:

      <path id="path1">
        ...
      </>
      <path id="path2">
        ...
      </>

and the called build file (`subbuild.xml`) also defines a `<path>` with the id `path1`, but `path2` is not defined:

      <ant antfile="subbuild.xml" inheritrefs="true" />

will not override `subbuild`'s definition of `path1`, but make the parent's definition of `path2` available in the subbuild.

      <ant antfile="subbuild.xml" />

as well as

      <ant antfile="subbuild.xml" inheritrefs="false" />

will neither override `path1` nor copy `path2`.

      <ant antfile="subbuild.xml" inheritrefs="false" >
        <reference refid="path1" />
      </ant>

will override `subbuild`'s definition of `path1`.

      <ant antfile="subbuild.xml" inheritrefs="false" >
        <reference refid="path1" torefid="path2" />
      </ant>

will copy the parent's definition of `path1` into the new project using the id `path2`.

Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.