ANT Import Task

Introduction

One way to write re-usable/extensible ANT scripts, is to make use of the the import task. This task allows you to easily override targets of the same name and build upon more foundational scripts, like layers:

Layers

(each top layer inherits from the layer below it)

The following illuminates this task a bit more and assumes you are familiar with ANT scripting.

Getting Started

You might want to download and play with these example scripts.

Targets & Outputs

If you look at the one.xml script, you will see that the following targets are called in this order:

  1. init
  2. compile
  3. one
  4. assemble
  5. finalize

The output from the one.xml script yields the following:

One Output

With the two.xml script, you will see that it has the same targets as the one.xml script called in the same order (minus the one target) as shown here:

  1. init
  2. compile
  3. assemble
  4. finalize

The output from the two.xml script yields the following:

Two Output

Analysis

The significance of the two.xml output, shown above, is where the “init” and “compile” targets depend on targets originally defined in the one.xml script:

Two.xml (target dependencies)

Note that each dependency is qualified with a “one.” prefix. For example: “one.init” and “one.compile”. You need to do this otherwise ANT will think you are referring to targets of the same name as defined in two.xml.

The “one” prefix come from the name of the project as shown here:

One (project info)

Conclusion

None of what has been discussed here is ground breaking but sometimes it is helpful to remember how useful the import task really is. I also believe that in some cases it is not used more when it should be. If you build a well written foundational script (lowest level to be imported) then you should be able to build upon that script with more complicated scripts.

Friday, May 4th, 2007 Software

No comments yet.

Leave a comment

You must be logged in to post a comment.

Search

 

Categories