有没有办法将参数传递给ant任务命令?

时间:2011-03-25 19:15:11

标签: ant parameters

我使用Ant来构建我的Android应用程序。我希望能够做到这一点:

ant debug android-market; //build the debug version for android-market;
ant debug motorola-market; //Builds debug version for motorola-market;
ant release android-market; //etc.

有没有办法从我的自定义ant调试/发布任务中检测到“android-market”参数?

我不想使用Dparam=value,因为那样看起来不太干净。

3 个答案:

答案 0 :(得分:4)

此语法用于一次调用多个目标。所以你可以使用

ant android-market debug

并使android-market目标设置调试目标中使用的属性,以确定要构建的版本:

<project basedir="." default="debug">
  <target name="android-market">
    <property name="market" value="android"/>
  </target>

  <target name="debug">
    <echo message="debugging for the following market : ${market}"/>
  </target>
</project>

> ant android-market debug
> android-market:
> debug:
> [echo] debugging for the following market : android

答案 1 :(得分:1)

  

我不想使用-Dparam = value,因为那样看起来不太干净。

我认为你应该克服自己的偏好。但添加一个“帮助”目标,描述其他目标接受的参数。

答案 2 :(得分:0)

JB的答案完全有效但我想找到一种方法来获得默认值。我在这里找到了一个名叫Mike Schilling的人的回答:http://www.velocityreviews.com/forums/t137033-is-it-possible-to-alter-ant-properties-after-theyve-been-initialized.html

所以我最终得到了类似的东西:

<project basedir="." default="debug">
    <target name="set-defaults">
        <property name="market" value="android"/>
    </target>

    <target name="motorola-market">
        <property name="market" value="motorola/>
    </target>

    <target name="debug" depends="set-defaults">
        <echo message="debugging for the following market : ${market}"/>
    </target>
</project>

所以你可以为android设置ant debug或者为motorola设置ant motorola-market debug

相关问题