Maven inherited attributes from parent POM

10,714

Solution 1

The child pom inherits everything from the parent pom. If you need to set meaningful values in the child pom then you will need to override the values in the parent pom.

From the Docs:

When a project specifies a parent project, Maven uses that parent POM as a starting point before it reads the current project’s POM. It inherits everything, including the groupId and version number.

Solution 2

Most elements from the parent POM are inherited by its children. Two elements that aren't inherited are artifactId & name. (Also, any plugins which explicitly set <inherited>false)

Share:
10,714
Hilikus
Author by

Hilikus

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - M. Fowler

Updated on July 19, 2022

Comments

  • Hilikus
    Hilikus almost 2 years

    I am trying to find an authoritative list of which elements get inherited from a parent POM. Based on this page

    When you inherit a POM, you can choose to live with the inherited POM information or to selectively override it. The following is a list of items a Maven POM inherits from its parent POM:

    • identifiers (at least one of groupId or artifactId must be overridden.)
    • dependencies
    • developers and contributors
    • plugin lists
    • reports lists
    • plugin executions (executions with matching ids are merged)
    • plugin configuration

    But when I see the effective POM in one of my projects I see it also inherits inceptionYear, description (which is a problem, this should be a description of the POM that contains it, not of its children. What's the point of all children having a description like "The root of all POMs")

    So is there an actual list or does it just inherit everything from the parent pom? i use some of these properties in the artifact's manifest so I want to add meaningful values

  • Hilikus
    Hilikus over 11 years
    can you link the source of your quote please. i missed that part and actually found a different answer, as mentioned in my question
  • Hilikus
    Hilikus over 11 years
  • Trunk
    Trunk almost 5 years
    And yet - though Maven plugins on IntelliJ and Eclipse force you to give groupid, artifactid and version - the actual XML schema for the POM has minOccurs=0 for each of these elements . . . maven.apache.org/xsd/maven-4.0.0.xsd