【问题标题】:Pass ant target to multiple build.xml files in subdirectories将 ant 目标传递给子目录中的多个 build.xml 文件
【发布时间】:2009-05-04 10:15:37
【问题描述】:

我有一个包含多个模块的项目,每个模块都在自己的目录中。每个模块都有自己的 ant 构建文件(build.xml)

在根目录中我设置了一个通用的构建文件,它以正确的顺序调用每个模块的构建文件。

<?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>

现在每个模块也有一个“干净”的目标,所以我添加了这些行:

 <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>

还有更多这样的目标。有没有办法重写构建文件以避免这种重复?我一直在寻找包含活动目标的内置属性,但找不到。

【问题讨论】:

    标签: ant build


    【解决方案1】:

    为什么不使用antcall 调用引用所有子目录的目标,并参数化要调用的目标。例如

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

    然后:

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

    所以这允许您参数化对子目录的调用。如果您添加一个新的子目录,您只需将该子目录添加到“doStuffToSubdirs”目标(我也会重命名它!)

    【讨论】:

    • 虽然它应该是
    • 我现在会更正它。谢谢提醒(我承认我没有测试过:-)
    【解决方案2】:

    在您的 commonbuild.xml 中放置一个干净的目标,在子文件中只需导入您的父 build.xml

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

    现在您将能够在您的子构建中调用 clean 目标。您还可以通过在您的任何子构建中创建一个干净的目标来覆盖此目标。

    【讨论】:

    • 如果我理解正确,那就假设“干净”目标在每个子目录中执行完全相同的操作。但事实并非如此,尤其是对于我可能希望以相同方式调用的其他目标。
    • np,这也是一个有用的技巧,我可能改天使用 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多