manual/Tasks/import.html [200:285]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The short version: Use import if you intend to override a target, otherwise use include.

When import is used, the imported targets are available by up to two names: their "normal" name without any prefix and potentially with a prefixed name (the value of the as attribute or the imported project's name attribute, if any).

When include is used, the included targets are only available in the prefixed form.

When import is used, the imported target's depends attribute remains unchanged, i.e. it uses "normal" names and allows you to override targets in the dependency list.

When include is used, the included targets cannot be overridden and their depends attributes are rewritten so that prefixed names are used. This allows writers of the included file to control which target is invoked as part of the dependencies.

It is possible to include the same file more than once by using different prefixes; it is not possible to import the same file more than once.

Examples

nested.xml shall be:

<project>
  <target name="setUp">
    <property name="prop" value="in nested"/>
  </target>

  <target name="echo" depends="setUp">
    <echo>prop has the value ${prop}</echo>
  </target>
</project>

When using import like in

<project default="test">
  <target name="setUp">
    <property name="prop" value="in importing"/>
  </target>

  <import file="nested.xml" as="nested"/>

  <target name="test" depends="nested.echo"/>
</project>

Running the build file will emit:

setUp:

nested.echo:
     [echo] prop has the value in importing

test:

When using include like in

<project default="test">
  <target name="setUp">
    <property name="prop" value="in importing"/>
  </target>

  <include file="nested.xml" as="nested"/>

  <target name="test" depends="nested.echo"/>
</project>

Running the target build file will emit:

nested.setUp:

nested.echo:
     [echo] prop has the value in nested

test:

and there won't be any target named echo on the including build file.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - manual/Tasks/include.html [195:280]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The short version: Use import if you intend to override a target, otherwise use include.

When import is used, the imported targets are available by up to two names: their "normal" name without any prefix and potentially with a prefixed name (the value of the as attribute or the imported project's name attribute, if any).

When include is used, the included targets are only available in the prefixed form.

When import is used, the imported target's depends attribute remains unchanged, i.e. it uses "normal" names and allows you to override targets in the dependency list.

When include is used, the included targets cannot be overridden and their depends attributes are rewritten so that prefixed names are used. This allows writers of the included file to control which target is invoked as part of the dependencies.

It is possible to include the same file more than once by using different prefixes; it is not possible to import the same file more than once.

Examples

nested.xml shall be:

<project>
  <target name="setUp">
    <property name="prop" value="in nested"/>
  </target>

  <target name="echo" depends="setUp">
    <echo>prop has the value ${prop}</echo>
  </target>
</project>

When using import like in

<project default="test">
  <target name="setUp">
    <property name="prop" value="in importing"/>
  </target>

  <import file="nested.xml" as="nested"/>

  <target name="test" depends="nested.echo"/>
</project>

Running the build file will emit:

setUp:

nested.echo:
     [echo] prop has the value in importing

test:

When using include like in

<project default="test">
  <target name="setUp">
    <property name="prop" value="in importing"/>
  </target>

  <include file="nested.xml" as="nested"/>

  <target name="test" depends="nested.echo"/>
</project>

Running the target build file will emit:

nested.setUp:

nested.echo:
     [echo] prop has the value in nested

test:

and there won't be any target named echo on the including build file.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -