代码之家  ›  专栏  ›  技术社区  ›  amarillion

将ant目标传递到子目录中的多个build.xml文件

  •  7
  • amarillion  · 技术社区  · 16 年前

    我有一个有多个模块的项目,每个模块都在自己的目录中。每个模块都有自己的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>
    

    还有更多这样的目标。是否有方法重写生成文件以避免此重复?我已查找包含活动目标的内置属性,但找不到它。

    2 回复  |  直到 14 年前
        1
  •  7
  •   martin clayton egrunin    14 年前

    为什么不使用 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>
    

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

        2
  •  2
  •   Nuno Furtado    16 年前

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

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

    现在,您将能够在您的子版本中调用clean目标。也可以通过在任何子生成中创建干净的目标来覆盖此目标。