Skip to content

Nested Ant Properties

March 29, 2010

Ant doesn’t support nested properties (directly). After some searching I came across this solution. I’m putting it here mainly as a reminder to myself if I ever need to do this gain.

Just to define the problem… say I want to set the version number to be dependent on the project. Naturally you might think to try something like this…

<property name="project.version" value="${${}.project.version}"/>

…but it doesn’t work. The solution that does work is the following:

<macrodef name="propertycopy">
  <attribute name="name"/>
  <attribute name="from"/>
    <property name="@{name}" value="${@{from}}"/>
<property name="project.version.prop" value="${major.project}.project.version"/>
<propertycopy name="project.version" from="${project.version.prop}"/>

Ugly, but workable.

From → Build

One Comment
  1. Pradeep permalink

    u rock

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: