ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Dawson <>
Subject Ant 1.5... importing targets from other projects (implementation attached)
Date Fri, 05 Oct 2001 16:09:07 GMT
I've requested the ability to import targets from other projects in the
past, and I've been shot down before, but that won't stop me, especially now
that I've seen something very much like this request in the approved section
of the Ant 2.0 features.  :-)

First, some background: If any of you have taken a look at the
jakarta-taglibs build system lately, you'll see a number of loosely
confederated projects that have very similar needs for a build, but not all
are exactly the same.  Because Ant does not provide a simple means for
creating and importing a standard build file, each project had started with
a template, and sort of gone off on its own from there.

Around last may, I came up with an approach which is being used now in
jakarta-taglibs, that requires the use of an xml include and having each
target call a pre- and post- target based on a property definition that
could be overridden in a subproject. While much better than the previous
chaos, it is still quite ugly because (1) the xml include is not terribly
readable, and (2) the pre/post target properties are a bit non-intuitive as

Realistically, what is needed is the ability to import a set of standard
tasks and override them. e.g.

---------- common.xml
<target name="install">

<target name="compile">

---------- build.xml
<antimport file="common.xml" collisionprefix="common"/>

<target name="install">
  <antcall target="common.install"/>
  <echo>do some more stuff after the standard stuff</echo>


>From now, at the command line, I should be able to type "ant install" or
"ant compile", and both should work just fine. In the case of compile, the
javac occurs just as if the javac target were inside build.xml. In the case
of install, ant would simply call the normal install target, and if the
build.xml implementor hadn't added the antcall to "common.install", it would
have been a full override.

Implementing this is a breeze... I've attached a starter implementation that
works just fine except I haven't implemented the collisionprefix stuff yet.
It simply works by loading the project from the other file, and creating a
wrapper target with the same name containing an <ant> task that calls the
original target in the original file.

I'd like to see what interest there might be in adding this to Ant 1.5 --
its already listed as a 2.0 requirement, but as you can see, there's no
rocket science here, the implementation is actually quite simple.  I can
tell you from experience, this would make the jakarta-taglibs project (with
over 30 subprojects) much much cleaner.



View raw message