[英]Is there a way to pass parameters into a ant task command?
I use Ant to build my Android application. 我使用Ant来构建我的Android应用程序。 I want to be able to do this:
我希望能够做到这一点:
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.
Is there a way to detect that "android-market" parameter from within my custom ant debug/release task? 有没有一种方法可以从我的自定义ant调试/发布任务中检测到“ android-market”参数?
I would prefer not to use Dparam=value
, since that is less clean looking. 我不希望使用
Dparam=value
,因为那样看起来不太干净。
This syntax is used to invoke multiple targets at once. 此语法用于一次调用多个目标。 So you could perhaps use
所以你也许可以使用
ant android-market debug
and make the android-market target set a property used in the debug target to identify which version to build: 并使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
I would prefer not to use -Dparam=value, since that is less clean looking.
我不希望使用-Dparam = value,因为这样看起来不太干净。
I think you should get over your preferences. 我认为您应该克服自己的偏好。 But add a 'help' target that describes the parameters accepted by the other targets.
但是添加一个“帮助”目标,该目标描述其他目标接受的参数。
JB's answer totally worked but I wanted to find a way to have a default. JB的答案完全奏效,但我想找到一种默认方法。 I found an answer to that here by someone named Mike Schilling: http://www.velocityreviews.com/forums/t137033-is-it-possible-to-alter-ant-properties-after-theyve-been-initialized.html
我在这里找到了一个叫Mike Schilling的答案: http : //www.velocityreviews.com/forums/t137033-is-it-possible-to-alter-ant-properties-after-theyve-been-initialized.html
So I ended up having something like this: 所以我最终遇到了这样的事情:
<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>
So you could do ant debug
for android or ant motorola-market debug
for motorola. 因此,您可以针对Android进行
ant debug
,也可以针对ant motorola-market debug
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.