Apache Commons logo

Help with Maven Ant Mojos

The best sources of information are Developing Ant Plugins for Maven 2.x and Maven: The Definitive Guide: Chapter 11 Writing Plugins.

New Ant Scripts

Each ant script requires two files, which have to be named following the conventions for ant plugins:

  • An ant build file
    • [naming convention: basename.build.xml]
  • A mapping document which wires the build file into maven's plugin framework
    • [naming convention: basename.mojos.xml]

So if you want to add a new foo-bar ant script you would create a foo-bar.build.xml ant script file and foo-bar.mojos.xml mapping document.

Both these files should be located in the src/main/scripts directory.

If you want to access variables from the component's pom.xml in the ant script then you need to do two things in the mapping document:

  • Add the <requiresProject>true</requiresProject>
  • Add <parameter> elements for each of the variables you want to use.

Goal Prefix

This plugin uses commons as the goal prefix. So if you add a new foo-bar goal, then it can be executed on the command line using mvn commons:foo-bar. This prefix is defined in this plugin's pom.xml.

Modifying Existing Scripts

Not alot to say about this except, if you need access to additional variables from the component's pom.xml in the ant build script then you will need to define additional parameters for these in the associated mapping document.

Debugging

The message level for ant is info by default. Running the plugin goal using a message level of debug can help in discovering problems - for example:

    mvn commons:jira-page -DantMessageLevel=debug