将 ant 目标传递给子目录中的多个 build.xml 文件 [英] Pass ant target to multiple build.xml files in subdirectories

查看:29
本文介绍了将 ant 目标传递给子目录中的多个 build.xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

In the root directory I've set up a general build file that calls the build file of each module in the right 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" target, so I add these 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 targets like that. Is there a way to rewrite the build file to avoid this duplication? I've looked for a built-in property that contains the active target, but I couldn't find it.

推荐答案

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

Why not use antcall to call a target that references all your subdirs, and parameterise the target to be called. e.g.

 <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' 目标(我也会重命名它!)

so this allows you to parameterise the calls to your subdirs. If you add a new subdir, you only have to add that subdir to the 'doStuffToSubdirs' target (I would rename that as well!)

这篇关于将 ant 目标传递给子目录中的多个 build.xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆