2

I'd like to use Ant property files such that one property file inherits from another but I'm not sure it's possible.

For example:

base.properties: prop1=base child.properties (inherit from base.properties): prop1=child // this should override prop1 in base.properties 

I know that i can pass them via cmd line in the proper order to achive this but I'm hoping to achieve it by defining the inheritance within the files themselves.

Any idea how i can achieve this?

Thanks!

2 Answers 2

2

Ant properties are immutable. If you load child.properties first, all property definitions from it will be used instead of base.properties.

This is also why command line overrides work.

So load your files in the order from child to parent and you will have some resemblance of hierarchy.

Sign up to request clarification or add additional context in comments.

1 Comment

right. they essentially override the base in that case, if the property files are ordered correctly. but is there a way to override based on inheritance defined within the file?
2

What you are looking for is not supported in core Ant.

A typical pattern would be to load properties in your build file in a cascading fashion, for example something like this:

<property file="${user.home}/${product}/${product.version}/build.properties"/> <property file="${user.home}/${product}/build.properties"/> <property file="${user.home}/build.properties"/> <property file="build.properties"/> 

The files do not all need to exist. Whichever files do exist are loaded in that order. This gives simple way to selectively override properties.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.