Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Build 为一组选定的项目执行选定的ant任务_Build_Ant - Fatal编程技术网

Build 为一组选定的项目执行选定的ant任务

Build 为一组选定的项目执行选定的ant任务,build,ant,Build,Ant,我已经在ant中为我们的游戏定义了目标,例如清理、构建ios、构建android、部署ios、部署android等。现在我想定义一组代表我们游戏的新目标,比如game1、game2、game3 我的目标是能够使用一组目标游戏和一组目标任务来启动ant,以便对每个选定的游戏执行每个选定的任务 示例伪代码:Foreach[game1,game3]:清理、构建ios、部署ios 如何使用ant实现这一点?要求是定义通过目标选择哪些游戏和哪些任务,而不是将它们写入手动更改的文件。如果您有多个共享类似结构

我已经在ant中为我们的游戏定义了目标,例如清理、构建ios、构建android、部署ios、部署android等。现在我想定义一组代表我们游戏的新目标,比如game1、game2、game3

我的目标是能够使用一组目标游戏和一组目标任务来启动ant,以便对每个选定的游戏执行每个选定的任务

示例伪代码:
Foreach[game1,game3]:清理、构建ios、部署ios


如何使用ant实现这一点?要求是定义通过目标选择哪些游戏和哪些任务,而不是将它们写入手动更改的文件。

如果您有多个共享类似结构的子项目,则
子任务非常有用

在main build.xml中,定义一个目标,该目标与所有通用的构建目标一起在游戏子目录上摩擦所需的构建目标

<target name="deploy-all">
    <subant target="deploy">
        <dirset dir="." includes="game-*" />
    </subant>

    <echo message="All games deployed." />
</target>

<target name="deploy" depends="deploy-ios,deploy-android">
    <echo message="${ant.project.name} build complete." />
</target>

<target name="clean">
    <echo message="Cleaning ${ant.project.name}" />
</target>

<target name="build-ios" depends="clean">
    <echo message="Building iOS ${ant.project.name}" />
</target>

<target name="build-android" depends="clean">
    <echo message="Building Android ${ant.project.name}" />
</target>

<target name="deploy-ios" depends="build-ios">
    <echo message="Deploying iOS ${ant.project.name}" />
</target>

<target name="deploy-android" depends="build-android">
    <echo message="Deploying Android ${ant.project.name}" />
</target>

然后,用户可以运行一个命令,该命令可以选择性地传递
游戏的值。包括
和/或
游戏。排除
。如果未指定这些属性,则上面由
属性任务定义的值将用作默认值。

谢谢,这会有所帮助。尽管我仍然无法轻松地选择要运行任务的众多游戏中的哪一个。如果我理解你的例子是正确的,你建议创建一个subant来构建所有游戏,但我的目标是只构建选定的游戏。我想我可以创建子任务来结合每个目标和游戏,但这需要大量的编写。有没有更简单的方法告诉ant构建目标“部署”,但只针对选定的游戏,而不是所有游戏?比如说,选择我想要包含的子组件构建文件,而不是包含游戏-*。。?Thanksupant迭代一个资源集合(在本例中是一组目录),因此,如果您想选择构建哪些子项目,可以使用该资源集合的include和excludes。我将编辑答案以显示示例。
<project name="game-1" default="build">
    <import file="../build.xml" />

    <echo message="=== Building Game 1 ===" />
</project>
<project name="game-2" default="build">
    <import file="../build.xml" />

    <echo message="=== Building Game 2 ===" />
</project>
    <property name="game.includes" value="game-*" />
    <property name="game.excludes" value="" />

    <subant target="deploy">
        <dirset dir="." includes="${game.includes}" excludes="${game.excludes}" />
    </subant>