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