Ant-为所有子目录运行Build.xml

| 我在最顶层有一个build.xml,我希望脚本为每个子目录运行一个目标,并将子目录名称作为参数传递给ANT目标。 你能帮我吗 ?/?? 谢谢     
已邀请:
看一下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>
  该片段构建文件将在项目目录的每个子目录中运行ant,在该子目录中可以找到一个名为build.xml的文件。在subant调用的ant项目中,属性build.dir的值将为subant1.build。     
这可能就是您要寻找的, 将此作为您的目标之一放在父build.xml中
<target name=\"executeChildBuild\">

    <ant antfile=\"sub1/build.xml\" target=\"build\" />
    <ant antfile=\"sub2/build.xml\" target=\"build\" />

</target>
    
如果您想在ant构建文件中执行此操作,则可以使用Ant Contrib \的任务来遍历子目录列表并为每个子目录执行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,但是它接近我想做的事情。     
如果我正确阅读了该问题,则可能是您要查找的内容。 所以举个例子
<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调用此代码时,您可以在命令行中输入以下内容:
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
当然,您需要确保用作参数的目录名确实存在,否则构建将失败。 您还可以始终通过将值添加到build.properties文件中来提供要使用的变量。     

要回复问题请先登录注册