Can a parent property be made final so that it cannot be overridden by a child

25k views Asked by At

Is it possible to make properties in parent pom not overridable by the module pom?

For example:

if module pom says:

<properties>
    <someProperty>some value to be replaced</properties>
</properties>

and parent pom already has it declared as:

<properties>
    <someProperty>strongValue</someProperty>
</properties>

effective module pom should be:

<properties>
    <someProperty>strongValue</someProperty>
</properties>

but it is currently expected to be this:

<properties>
    <someProperty>some value to be replaced</properties>
</properties>

If yes then how to achieve it?

3

There are 3 answers

4
Robert Scholte On BEST ANSWER

No, you can't. The idea is that if it shouldn't be possible to override a value, don't use a property. If you have no other option, you might want to force it with http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html which will break the build if a property has a different value than expected.

7
user944849 On

Only way I know to do this for sure is to define the property on the command line, e.g. mvn -DsomeProperty=strongValue <mvn goals/phases here>.

You might experiment with profiles defined in the parent; I suspect that won't help.

1
kanaparthikiran On

A child POM can overwrite the value of a property defined in a parent pom. So it works by just putting a section in the child POM and set the values to desired values.