Ant - 为所有子目录运行Build.xml
这可能是你在寻找什么,
把这个作为目标之一,你的父母的build.xml
<target name="executeChildBuild">
<ant antfile="sub1/build.xml" target="build" />
<ant antfile="sub2/build.xml" target="build" />
</target>
不是,我想要一个顶级build.xml遍历所有子目录,并在顶级build.xml中运行目标方法,并将子目录名作为参数。子目录不会有单独的build.xmls。 – eleshmistry 2011-05-23 14:38:15
做你的意思是这样,伪代码: – Adelave 2011-05-23 14:44:21
没错,但在蚂蚁 – eleshmistry 2011-05-23 14:48:24
如果你想做到这一点在ant build文件,你可以使用Ant Contrib's for task遍历子目录列表并为每个子目录执行ant任务。
<for param="subdir">
<dirset dir="${build.dir}">
<include name="./**"/>
</dirset>
<sequential>
<subant target="${target}">
<property name="subdir.name" value="@{subdir}"/>
</subant>
</sequential>
</for>
我没有测试这个代码,因为没有安装ant,但它接近你想要做的,我想。
我已经取得了一些进展,我想使用Subant,但有一个问题:
已更新,代码示例 – artplastika 2011-05-23 15:47:39
如果我正确地阅读了这个问题,这可能是你正在寻找的东西。
因此,对于你的例子...
<target name="do-all">
<antcall target="do-first">
<param name="dir-name" value="first"/>
<param name="intented-target" value="init"/>
</antcall>
<antcall target="do-first">
<param name="dir-name" value="second"/>
<param name="intented-target" value="build"/>
</antcall>
<antcall target="do-first">
<param name="dir-name" value="third"/>
<param name="intented-target" value="compile"/>
</antcall>
</target>
<target name="do-first">
<echo>Hello from ${dir-name} ${intented-target}</echo>
<ant antfile="${dir-name}/build.xml" target="${intented-target}"/>
</target>
当你从蚂蚁调用这个,你会在命令行输入:
ant do-all
和你的输出应该看起来像此:
do-all:
do-first:
[echo] Hello from first init
do-first:
[echo] Hello from second build
do-first:
[echo] Hello from third compile
BUILD SUCCESSFUL
Total time: 1 second
您当然需要确保您用作param的目录名实际存在,否则构建将失败。
您也可以始终通过将值添加到build.properties文件来提供您想要使用的变量。
看看subant任务。从这个页面:
<project name="subant" default="subant1">
<property name="build.dir" value="subant.build"/>
<target name="subant1">
<subant target="">
<property name="build.dir" value="subant1.build"/>
<property name="not.overloaded" value="not.overloaded"/>
<fileset dir="." includes="*/build.xml"/>
</subant>
</target>
</project>
这个片段构建文件将运行在项目目录,其中一个文件名为build.xml可以发现每个子目录蚂蚁。属性build.dir将具有值subant1。建立在subant调用的ant项目中。
你是什么意思下的“脚本”:蝙蝠,SH等? – artplastika 2011-05-23 14:30:59