ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frank Wilson <>
Subject Importing Ant build files on the classpath with Maven
Date Mon, 10 May 2010 13:46:07 GMT
I've been looking at various ways of importing other ant buildfiles
from the classpath to reduce coupling in my multimodule build. This would
allow me to checkout only the code and build files I intend to

I've been looking at using Maven to facilitate this. My solution uses
the maven ant-run plugin to run a build.xml file with a classpath
that includes a file echo.xml on which build.xml depends (see diagram below).

However, this requires a few modifications to both ant and the ant-run

The modification to the ant-run plugin is pretty trivial, we
just need it to use ant 1.8.1 so we can put <javaresource/> types inside
<import/>, this basically a change to the ant-run pom.xml so that we bring
ant 1.8.1 onto the classpath instead of 1.7.1. We then reinstall the
ant-run plugin into our

Somewhat more siginificant is the change to ant. To support this mechanism
we need to be able inherit references in the file being called by the
"Ant" task. The Ant tasks supports this, but what is not clear is that
it will not export references in the preamble of an ant build file.
References are only available within targets. However, since the
<import/> element
cannot exist within a <target/> making references in the preable is really
necessary in order for this to work.

Hence, I made a change to the "Ant" task, so that it brings in import references
before the file (build.xml in the example) is parsed. Consequently, the
references should be available in the preamble.

The example I have given seems to work ok with this code change.

I would like to ask if this tweak to the ant task code is a good idea and
whether there is any chance of it or something similar being adopted
in ant itself.

The change is only one line, but I am worried I might be missing some serious

I attach a patch for the ant task which should apply cleanly to the
ANT_181 tag on svn.


BuildCommon Project:

| |
| +-resources
|   |
|   +echo.xml // the ant file I want to import.
+-pom.xml // bog standard pom, builds a jar which has echo.xml at the root

<project name="echo">

<target name="echo">
<echo>Hello Modular Ant World!! </echo>


BuildClient Project:

+-pom.xml // standard pom, with ant-run executing build.xml in "compile" phase
+-build.xml // the ant file with classpath dependencies that we want to run.

// ... standard pom header


<ant antfile="build.xml" target="echo" inheritrefs="true"/>


// ... dependencies

<project name="BuildClient">

<javaresource name="echo.xml">
<classpath refid="maven.compile.classpath" />


View raw message