简体   繁体   中英

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

I use Ant to build my Android application. 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?

I would prefer not to use Dparam=value , since that is less clean looking.

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:

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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