Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding module properties from parent POM in Maven

Tags:

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?

like image 888
zacheusz Avatar asked Sep 05 '13 16:09

zacheusz


People also ask

How do you override a parent pom?

Overriding configurations from a parent pom can be done by adding the combine. self="override" attribute to the element in your pom.

Are plugins inherited from parent pom?

Plugins declared outside of <pluginManagement> are inherited by child POMs, by default. Their settings can be overridden by each child if desired.

Are Maven properties inherited?

Maven supports project inheritance. You can create a parent project that contains properties child projects have in common, and child projects inherit those properties from the parent project.


2 Answers

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.

like image 163
Robert Scholte Avatar answered Sep 28 '22 01:09

Robert Scholte


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.

like image 29
user944849 Avatar answered Sep 28 '22 03:09

user944849