Chapter 17. Writing Ant tasks

 

This chapter covers:

  • 17.1 What exactly is an Ant task?
  • 17.2 Introducing Ant’s Java API
  • 17.3 A useful task: <filesize>
  • 17.4 Testing tasks with AntUnit
  • 17.5 More task attributes
  • 17.6 Supporting nested elements
  • 17.7 Working with resources
  • 17.8 Delegating to other tasks
  • 17.9 Other task techniques
  • 17.10 Making an Antlib library
  • 17.11 Summary

There comes a moment where it becomes clear that Ant doesn’t do everything you need. It may be that something minor is missing, such as not being able to pass all the options you want to <junit> or <java>. It may be that something major is absent, like having no way to run a custom test framework. It may even be that a common Ant task doesn’t work quite right. This happens to everyone and there’s always a solution.

Ant can be extended through Java classes, and it takes only a small amount of Java coding to write a new Ant task. If the problem lies in the actual Ant source itself, then the fact that an entire Ant source tree is a download away comes into play. If Ant doesn’t work right, then it can be fixed. However, this isn’t something we advocate—not yet. Ant can be extended without rebuilding it, in many ways:

  • Custom tasks, written in Java or a scripting language
  • Custom datatypes
  • Custom listeners, loggers, filters, selectors, and mappers
  • Hosting Ant inside another Java application

17.1. What exactly is an Ant task?

17.2. Introducing Ant’s Java API

17.3. A useful task: <filesize>

17.4. Testing tasks with AntUnit

17.5. More task attributes

17.6. Supporting nested elements

17.7. Working with resources

17.8. Delegating to other tasks

17.9. Other task techniques

17.10. Making an Antlib library

17.11. Summary

sitemap