tags:

views:

52

answers:

2

I'd like to set some properties in my ant build file, the names of which, are based on ant's build in properties. In particular, I'd like to set a property like:

<property name="${ant.project.name}.compiled" value="true" />

However, when I tried this the ${ant.project.home} portion was not expanded.

Is it possible to use the value of properties as the names of other properties, and if so, how?

A: 

I think the only way is to echo your values to a .properties file and then load them back. However, you should ask yourself if you really need it; when I last used ant I tried to do the same thing but concluded I didn't really need to.

Is

$ant.project.home.compiled

not just as useful?

Nathan Kidd
unfortunately $ant.project.home.compiled would probably not be useful to me. I really just need to set a flag that a project (the name of which I don't know in advance) has been compiled, so I can avoid the overhead of compiling it again
avjaz
Ant is intelligent enough to not recompile files. It checks the dates on the sources and compares to the classes and only recompiles if needed.
Rob Spieldenner
A: 

It can be done, a bit ugly, though. You need the < propertycopy > task from ant-contrib for this. The following shows an example

<property name="projectNameCompiled" value="${ant.project.name}.compiled" /> 
<property name="${projectNameCompiled}" value="true" /> 
<propertycopy property="final" from="${ant.project.name}.compiled" /> 

The property final contains the value true.

akr