tags:

views:

646

answers:

4

How do you call a specific target in all build.xml located in all subdirectories using wildcards (ie not hard coding the subdirectory names)? The below answer is hardcoded. Is there a way to do it without hardcode?

Similar to this question: Pass ant target to multiple build.xml files in subdirectories

A: 

I'll setup different properties within my build.properties file. I use these to dynamically build paths in my targets.

Define the location of your build.properties file:

  <!--  all properties are in build.properties --> 
  <property file="build.properties" />

Use those properties in your targets:

Properties in the build properties are similar to setting up an .ini file:

project.rootdir=c:/Deploy
project.tempbuilddir = c:/Deploy/Temp/Inetpub
project.builddir=c:/Deploy/Inetpub
# Build prefix will be added to that tags urls (.../tags/${project.buildprefix}Build_${today.date})
project.buildprefix=ACA_

I guess you could use a dynamic file as your properties file, if necessary, as long as you define the proper path to the file. You could point it to a server-side file to dynamically write your properties file (ColdFusion, PHP, JSP, whatever).

Steve -Cutter- Blades
This doesn't do what I'm asking. I have a top level build.xml. I want it to call a task (ie clean) in all the build.xml in all subdirectories of the top level.
Tazzy531
A: 

I've used ant-contrib's foreach task to do something like this.

http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html

Nate
A: 

Sounds like a perfect candidate for the <subant> task.

A: 

Use the task like this:

<subant target="sometarget">
        <fileset dir="." includes="*/build.xml" />
</subant>

If you include an "inheritall" attribute (same as how it's used in but defaults the opposite), you can share all your current project's properties and everything too. This also makes it very easy to overwrite tasks defined in your main build.xml file if you need to.

Read more about it here.