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

发布于 2024-11-09 08:42:48 字数 96 浏览 0 评论 0原文

我有一个位于顶层的 build.xml,我希望脚本为每个子目录运行一个目标,并将子目录名称作为参数传递给 ANT 目标。

你能帮忙吗?/??

谢谢

I have a build.xml sitting at the top level and I want the script to run a target for each subdirectory and pass in the subdirectory name as a parameter to the ANT target.

Can you help ?/??

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坚持沉默 2024-11-16 08:42:48

查看 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。

Take a look at the subant task. From that page:

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

this snippet build file will run ant in each subdirectory of the project directory, where a file called build.xml can be found. The property build.dir will have the value subant1.build in the ant projects called by subant.

红焚 2024-11-16 08:42:48

这可能是您正在寻找的内容,

请将其作为您的父 build.xml 中的目标之一

<target name="executeChildBuild">

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

</target>

this is might be what you looking for,

put this as one of your target in your parent build.xml

<target name="executeChildBuild">

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

</target>
东北女汉子 2024-11-16 08:42:48

如果您想在 ant 构建文件中执行此操作,可以使用 Ant Contrib 的 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,但它接近我想的你想要做的。

If you would like to do it in ant build file, you could use Ant Contrib's for task to iterate over list of subdirectories and execute ant task for each of them.

<for param="subdir">
  <dirset dir="${build.dir}">
    <include name="./**"/>
  </dirset>
  <sequential>
    <subant target="${target}">
      <property name="subdir.name" value="@{subdir}"/>
    </subant>
  </sequential>
</for>

I didn't test this code since don't have ant installed, but it is close to what you're trying to do I suppose.

〆一缕阳光ご 2024-11-16 08:42:48

如果我正确地阅读了问题,这可能就是您正在寻找的。

因此,对于您的示例...

<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] 来自第一个 init 的问候

do-first:

[echo] 来自第二个构建的问候

先做:

[echo] 你好从第三次编译

构建成功
总时间:1 秒

您当然需要确保用作参数的目录名称实际存在,否则构建将失败。

您还可以随时通过将值添加到 build.properties 文件来提供要使用的变量。

If I read the question correctly, this may be what you are looking for instead.

So for your example...

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

When you are calling this from Ant, you would enter this at the command line:

ant do-all

and your output should look like this:

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

You will of course need to make sure that the directory name that you are using as a param actually exists, or the build will fail.

You can also always feed the variable that you want to use by adding the value to the build.properties file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文