ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Wall <>
Subject Re: AW: Conditional target execution based on prerequisite execution
Date Wed, 19 Feb 2003 02:06:45 GMT
Thanks.  That's a reasonable description, that should probably be up 
front in the Ant docs somewhere.  Unfortunately, it raises the bar for 
actually using "up-to-date" since you have to write a new task to get 

Does a target get noted as "not run" if all of its tasks decide they 
are up to date?

On Tuesday, February 18, 2003, at 01:38 PM, Dale Anson wrote:

> I think the problem/perception boils down to the difference between a 
> target and a task. Targets have no concept of "out of date". Target 
> can have dependencies, but the dependencies are targets that again 
> have no concept of "out of date". Tasks (including the property task) 
> can understand "out of date". The javac task is a good example in that 
> it only makes the compiler compile out of date source files. However, 
> tasks are not required to have any sense of "out of date". For 
> example, the echo task blindly prints a message to the output stream 
> everytime it is called, it doesn't know or care whether it already 
> printed the message. You can make a target "know" about being out of 
> date through use of properties and the if/unless target attributes. 
> This isn't automatic, you have to do the set up yourself. From your 
> examples, if you tell Ant to run target B, Ant will run target B and 
> target B will attempt to execute all of the tasks it contains every 
> single time it is called (depending, of course, on the result of the 
> if/unless tests). Note that target B only takes non-zero time to run 
> if the tasks it contains take non-zero time to run, and again, the 
> determination that a particular task in a target should execute is  
> performed by the task, not the target.
> Dale Anson
> Timothy Wall wrote:
>> The goal is not "run A before B" (although that may be a 
>> requirement).  The goal is "only run B if it is out of date".  Ant by 
>> default runs (almost) everything all the time.
>> If B takes nonzero time to run, I *only* want it to run if B is "out 
>> of date".  Normally, a target would be considered out of date if
>> a) any of its "depends" is out of date (and thus gets run)
>> b) some other prerequisites are not satisfied (i.e. .java is newer 
>> than .class, or the .jar file is not yet built)
>> Some examples of standard conditional execution:
>> idl parsing/code generation: generate .java code only if .idl files 
>> have been modified
>> jar file: only run jar if the class files it depends on have been 
>> regenerated
>> java compiler: only compile if .java is newer than .class
>> The last is the only thing that I've seen ant handle automatically, 
>> although I seem to have a knack for configuring things such that it 
>> recompiles everything every time.
>> On a complex project, typically you'll have many smaller targets with 
>> internal dependencies (and some with prerequisit targets as 
>> dependencies) and several overall targets that primarily consist of 
>> prerequisite target dependencies (a jar file or shared library, for 
>> instance).
>> On Tuesday, February 18, 2003, at 10:23 AM, 
>> wrote:
>>> When you use <target name="B" depends="A"/> the Ant framework will
>>> invoke A before B. Why setting a property?
>>> BTW the "onlyif" is <target if="propertyname"/>
>>> There is a unless="propertyname", too.
>>> Jan Matèrne
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View raw message