繁体   English   中英

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

[英]Is there a way to pass parameters into a ant task command?

我使用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 ,因为那样看起来不太干净。

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

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

我不希望使用-Dparam = value,因为这样看起来不太干净。

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

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 ,也可以针对ant motorola-market debug

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM