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, packages, etc.).
I would like to put all the different parameters into a single properties file and prefix each parameter with the environment it matches to.
For example, the properties file will contain dev.home-url = http://home_dev.com for the development environment and prod.home-url = http://home.com for the production environment.
I use the below to create a property that points to the properties file with a prefix of params:
<property file="parameters.properties" prefix="params" />
And to use a property, I use:
${params.home-url}
The problem comes when I need to add the prefix of the environment to the parameter.
It would end up looking like this, which obviously can’t be done:
${params.${env-prefix}.home-url}
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
build.xml
Executing the
exampletask outputs: