Thursday, June 14, 2007

Pom Inheritance

The problem:

You have a pom that contains configuration which you could reuse in another pom.

The solution:

You can inherit the configuration of a parent pom for use as the base of a new pom. This technique has many useful applications. One very important use is keeping configuration in one place. If you have a multitude of projects that inherit from one pom, then they will share some configuration. You can now change the configuration in the parent pom and all projects inheriting will get the changes. Think how much easier that makes changing a property that is inherited by 10, 15, maybe more projects.

So you are wondering how can I do such a great thing? It's easy just insert the parents pom's artifact id, group id, and version in your pom. You will put this information in the parent section of your pom. Here is what it will look like:
<parent>
<artifactId>Parent pom artifact id</artifactId>
<groupId>Parent pom group id</groupId>
<version>Parent pom's version</version>
</parent>
Thats all there is too it. Once you put that into your pom you inherit that pom's configuration. One last thing the parent pom must be in a reachable repository location.