ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicola Ken Barozzi <>
Subject Re: Ant 2 et al.
Date Wed, 10 Jul 2002 06:48:11 GMT

Nicola Ken Barozzi wrote:
> Erik Hatcher wrote:
>> ----- Original Message -----
>> From: "Nicola Ken Barozzi" <>
>>> IMHO it's better to use composition rather than inheritance, ie compose
>>> common build parts in your builds, like Java use Java packages.
>> I'm not entirely convinced of this yet, but I still need to ponder this
>> some.
>> Example:
>> I want to "inherit" a common web app project and add, say, XDoclet
>> generation of web.xml.
> import file="commonwebappproject.xml"
> import file="xdocletgeneration.xml"
>>> It's more a uses-a relationship rather than a is-a one.
>>> With imports you can modularize your builds.
>> But I don't want to import all the pieces for every build.  I want to 
>> inject
>> something into the dependency graph of an already pre-defined build.  How
>> would that play out with imports?
> Ah, "inject in the dependency graph" is a delicate point ;-)
> If you want to not import everything, make an intermediate
> buildfile that imports the single parts and have each of
> your projects import that.
> This means that each of your projects have access to the common build 
> targets with a single import, and can create others via composition, ie 
> by creating new targets and calling the original ones via antcall or 
> depends.
> You are not able to inject though a target in a defined place in the 
> imported tree though.
> It's specialization, what Maven does by giving hooks as pre and post 
> targets to existing ones.
> But this hides the dependency tree that is modifies.
> If it's pre-made but hidden it's ok, but if it's modified *and* hidden, 
> it hides what is happening and can bring to subtle errors.

Can one change his mind? Yes?
Ok, then I did ;-)

J.Pietschmann suggested me to look at xslt for inspiration, and now I 
agree that some kind of inherit can be done while keeping my concens in 

I will show you what I thought was needed, and instead how it can be done.

Suppose this target:

<target name="mytarget" depends="a,b,c">...</target>

is in a file that is imported by my buildfile.

Composition means:

<target name="mylocaltarget" depends="a,b,c">
   <antcall target="mytarget">

With this I can run "mylocaltarget" as an enhanced "mytarget".
What I /cannot/ do, as you pointed out, is have all the targets that 
depend on mytarget depend on mylocaltarget instead.
What could be done is callbacks, like:

<target type="pre" name="mytarget">

<target type="pre" name="mytarget">

Which I really don't like, since other imports can do the same in a 
difficult to control manner and things get out of control.

New way I like:

<target name="mytarget" inheritdeps="true" depends="additionaldeps">


I'll do this now and modify the patch accordingly :-D

Nicola Ken Barozzi         
             - verba volant, scripta manent -
    (discussions get forgotten, just code remains)

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message