Thu, 09. Oct 2003
This is another new kid on the Ant 1.6 block. <presetdef> will let you define your own default values for attributes and even for nested elements.
If you've always thought that <ant>'s inheritall attribute should be false by default, you are not only correct (but there is this backwards compatibility issue) but can now use
<presetdef name="better-ant"> <ant inheritall="false"/> </presetdef>and then use <better-ant> the same way you used <ant>. You can even set inheritall to true in your better-ant invocation if you want to.
The example from the manual uses <javac>:
<presetdef name="my.javac"> <javac debug="${debug}" deprecation="${deprecation}"> <src path="${gen.dir}"/> </javac> </presetdef>this shows two things:
- the debug and deprecation attributes take their default values from properties. If you use <my.javac> instead of <javac> throughout your build file, you can be sure that running ant -Ddebug=on will apply to all compilation tasks. No need to remember to put the customization into each task.
- The path ${gen.dir} will be added to <javac>s source path automagically.
While you may be able to override attributes set via <presetdef> when you use the task, you can not suppress child elements.
path: /en/Apache/Ant | #