2

I was curious how to decide whether our element in child pom will override the parent pom detail or just get added along with the parent pom inherited elements in child pom.

Let us take an example to understand :

For example, each dependency is uniquely identified by maven coordinates. In child pom, if a dependency has maven coordinate different from dependencies in parent pom, then no overriding happens and parent dependencies are added into child pom too.

Here we had a criteria of unique identification of an element in our maven xml which helped us to identify whether or not, overriding will take place.

Another example:

Let us take another example of <license> tag. Doing some experiment using effective pom, I came to know, that <licenses> are inherited.

<licenses>
    <license>
        <name>The Apache Software License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-3.0.txt</url>
        <distribution>repo</distribution>
    </license>
</licenses>

But if I change any one of <name>, <url>, <distribution>, overriding happens.

Are there any clear cut rules when overriding happens and when it does not happen (and parent elements gets appended with child elements) without generating effective pom every time and checking it?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Number945
  • 4,631
  • 8
  • 45
  • 83
  • How can `` be merged? – J Fabian Meier Apr 05 '19 at 12:53
  • @JFMeier Child pom takes `` of parent pom when not defined. So I think this is what the doc is saying by merge ? – Number945 Apr 05 '19 at 15:57
  • 1
    No, merging means that information of the parent POM is not overwritten, but put together with the information in the child POM. For example: You can define various dependencies in the parent POM and additional dependencies in the child POM, but the `` element of the child POM does not overwrite the one of the parent POM, but the elements of both are taken, i.e. merged. – J Fabian Meier Apr 05 '19 at 17:18
  • Thnx edited the question – Number945 Apr 05 '19 at 18:29
  • Why did you eliminate the link to the "merging list" from your question? – J Fabian Meier Apr 05 '19 at 18:35
  • @JFMeier , because it is no longer related to question. My question is about inheritance + overriding – Number945 Apr 05 '19 at 19:55
  • I recommend to read the documentation https://maven.apache.org/pom.html#Inheritance – khmarbaise Apr 06 '19 at 07:25
  • @khmarbaise , i read it but it does not define clear rules for when overriding happens . Take for example case of ``. The problem stems for how do you uniquely identify an maven element ? `` dont have id for example. I saw on github , you made commits in maven help plugin repo. So i hope , you might give us a clear view on how `mvn help:effective-pom` actually resolves it for each element. – Number945 Apr 06 '19 at 07:46

0 Answers0