Variables from properties file in Ant

前端 未结 1 1826
醉话见心
醉话见心 2021-01-15 19:49

I have an Android app that needs to be built for different environments (e.g., UAT, staging, production, etc.). Each environment needs different properties (e.g., URLs, pack

相关标签:
1条回答
  • 2021-01-15 20:12

    A frequently asked question about Ant is:

    How can I do something like <property name="prop" value="${${anotherprop}}"/> (double expanding the property)?

    The following Ant build file was inspired by that FAQ.

    parameters.properties

    dev.home-url = http://home_dev.com
    prod.home-url = http://home.com
    

    build.xml

    <project default="example">
        <property name="env-prefix" value="dev" />
        <property file="parameters.properties" prefix="params" />
    
        <macrodef name="propertycopy">
            <attribute name="name" />
            <attribute name="from" />
            <sequential>
                <property name="@{name}" value="${@{from}}" />
            </sequential>
        </macrodef>
    
        <target name="example">
            <propertycopy name="local.property" from="params.${env-prefix}.home-url" />
            <echo>${local.property}</echo>
        </target>
    </project>
    

    Executing the example task outputs:

    Buildfile: /workspace/build.xml
    example:
         [echo] http://home_dev.com
    BUILD SUCCESSFUL
    Total time: 405 milliseconds
    
    0 讨论(0)
提交回复
热议问题