This lesson explains and demonstrates how inheritance works with POM files.

We learned about Super POM and how all POMs extend from this base POM. Maven allows us to set any POM as the parent POM for a project. Introducing a parent POM can help extract out common configurations among an organization’s projects and consolidate them in a parent POM from which all other projects inherit. This avoids unnecessary repetition and verbosity. For example, a company can decide to have a parent POM that lists the organization’s internal Maven repositories thus allowing sub-teams to simply extend from the parent POM and not worry about the location of repositories. POM inheritance allows the following to be merged:

  • dependencies
  • developers and contributors
  • plugin lists (including reports)
  • plugin executions with matching ids
  • plugin configuration
  • resources

In essence, POM files at the bottom of the hierarchy declare that they inherit from a specific parent POM higher up in the hierarchy. The parent POM can then be used to share certain properties and details of configuration

Let’s dive into an example and see inheritance at work. We’ll work with Project3 with the directory structure shown as follows:

Get hands-on with 1200+ tech skills courses.