开发者

Can Ant property files define inheritance?

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 def开发者_JS百科ining the inheritance within the files themselves.

Any idea how i can achieve this?

Thanks!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜