ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject dynamic targets
Date Tue, 24 Oct 2006 03:28:35 GMT

Along the lines of....

Is it possible to create targets dynamically, deferring creation 
until such time as it is found that the project doesn't have the 
target already defined?  My use-case is using <subant> to iterate 
over sub-builds calling a target on each one.  My current strategy is 
to define <patternset>s for each type of project.  For instance, I 
add all web projects to a particular patternset and then reference 
that patternset when calling <subant>....

             <subant target="war" inheritAll="false">
                 <fileset dir=".">
                     <patternset refid="war.patternset"/>

As further fallback, individual builds may implement empty targets 
just so that they don't fail, just in case...

<target name="war">
     <echo message="Unimplemented target"/>

However, ideally, I'd like to be able to create the above target 
dynamically in the case that it isn't implemented already by the 
build.   This would have 2 benefits:

1.  I wouldn't have to bother creating the patternsets.  I'd just 
call all the build files and let them either build the war file or 
echo the "Unimplemented target" message.

2.  Individual builds that aren't web projects wouldn't have to have 
to know what a web project is.  If the only artifact generated is a 
simple jar library, it seems odd to have to implement a dummy "war" 
target simply because some external master build file might call "war" on it.

Instead of Ant failing with the following message...

Target `war' does not exist in this project.

...I'd like Ant to just run the above dynamically created target (not 
just the "war" target, but any target that might not exist), report 
the "Unimplemented target" message, and continue on.

So, is this possible?  Where/how do I hook into Ant to know the 
target isn't implemented and create it myself via a scriptdef before 
Ant gives me the build failure?


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

View raw message