简体   繁体   中英

Overriding module properties from parent POM in Maven

Is it possible to override module properties from parent pom without changing the module pom?

For example:

module pom (I can't change it at all):

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

parent pom:

<properties>
    <someProperty>strongValue</someProperty> <!-- some magic here -->
</properties>

effective module pom:

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

If yes then how to achieve it?

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM