Search code examples
antbuild-processbuild-automation

Ant - conditional statement


I'm using ant to build my app, and I want to have single process for dev/qa/prod versions of the app. I want to do be able to specify the build target from command line:

ant -Dbuildtarget=dev|qa|prod

and in build.xml check for the value of buildtarget and set an application specific base URL property based on the buildtarget specified by the user. I will subsequently set the correct runtime param using

    <copy file="pre.app.properties" tofile="./app.properties" overwrite="true">
        <filterset>
            <filter token="BASE_URL" value="${baseurl}" />
        </filterset>
    </copy>

What I am stuck on is how to express this in and build.xml ?

if buildtarget=='dev' 
    baseurl="http://my_dev_url"
else if buildtarget=='qa' 
    baseurl="http://my_qa_url"
else if buildtarget=='prod' 
    baseurl="http://my_prod_url"

I've searched around, but this seems to be difficult to do in ant. Any ideas ?


Solution

  • Perhaps you should try using the condition task of ant?