Passing ant target to multiple build.xml files in subdirectories

I have a project with several modules, each in its own directory. Each module has its own ant build file (build.xml)

In the root directory, I installed a shared assembly file that calls the assembly file of each module in the correct order.

<?xml version="1.0"?> <project name="bridgedb" default="all" basedir="."> <target name="all"> <ant dir="corelib"/> <ant dir="tools"/> <ant dir="makeGdb"/> <ant dir="cytoscape-plugin"/> </target> </project> 

Now each module also has a β€œclean” goal, so I add the following lines:

  <target name="clean"> <ant dir="corelib" target="clean"/> <ant dir="tools" target="clean"/> <ant dir="makeGdb" target="clean"/> <ant dir="cytoscape-plugin" target="clean"/> </target> 

And there are more such goals. Is there a way to overwrite the assembly file to avoid duplication? I was looking for an inline property that contains an active target, but I could not find it.

+7
build ant
source share
2 answers

Why not use antcall to call the target, which refers to all of your subdirects, and parameterize the target you want to call. eg.

  <antcall target="doStuffToSubdirs"> <!-- let clean --> <param name="param1" value="clean"/> </antcall> 

and then:

 <target name="doStuffToSubdirs"> <ant dir="corelib" target="${param1}"/> <ant dir="tools" target="${param1}"/> ...etc </target> 

therefore, it allows you to parameterize calls for your sub directors. If you add a new subdir, you will need to add this subdir to the doTuffToSubdirs target (I would rename it too!)

+7
source share

Put one clean target in your commonbuild.xml file and just import the parent build.xml file into child files

 <import file="${parent.dir}/commonbuild.xml" /> 

Now you can call a clean target in your child assemblies. You can also override this goal by creating a clean goal in any of your child collections.

+2
source share

All Articles