Is it possible to include several smaller pom files to create the parent pom file. (e.g. I would like to split the reporting, build sections into their own poms and include them in the parent pom) for managing them effectively
3 Answers
If you are using Maven 2, you can simply create several parent levels. The first pom.xml
(pom1) will define the basic properties (such as repositories for example). The second pom.xml
(pom2), which has pom1 as <parent>
, will define the reporting information. And so on... Finally, the "real" pom.xml
will inherit from the pom2 and will define its own properties.
You can create as many parent levels as you want (of course, it will be harder to maintain if you have 5 parent levels).
Note that Maven 3 talked about introducing the mixin concept, which will allow you to fragment your pom.xml
into several files, but it looks like that is not happening now until maven 4

- 2,446
- 1
- 14
- 12

- 79,475
- 49
- 202
- 273
-
1Guess, I will wait for the mixin feature in Maven 3 – Joe Feb 16 '10 at 07:03
-
@Joshua Maven 3 is already available, even if it is a beta release, it is quite stable. Maven 3 offer a 100% compatibility with Maven 2 `pom.xml`. It is already used by the latest versions of NetBeans, m2eclipse or IntelliJ. – Romain Linsolas Feb 16 '10 at 07:10
-
3Maven 3.0 doesn't offer mixins *yet*, however. – Brett Porter Feb 16 '10 at 08:18
-
Yes, indeed. Sorry for that ! – Romain Linsolas Feb 16 '10 at 08:30
-
1@BrettPorter does the latest version (3.04) of maven support mixin? – hugemeow Sep 18 '12 at 20:21
-
Everything's cool, but the first paragraph is such a good example of a description that fits better into a diagram. – Matthias Jul 26 '18 at 06:32
-
Forgive me for being naïve, but I would love to see an example for what has been mentioned here for Maven 2. Like a little before and after example. – The Next Programmer Dec 10 '21 at 20:26
Not quite. You can't include reporting and build sections defined in smaller POMs, you can only inherit them from a parent POM.
If your POM is getting too large, it is possible (and recommended) to arrange your dependencies into logical groups. For example, for a GWT project, you could create a new POM for all of your persistence related to GWT as follows:
<project>
<groupId>org.yourcompany</groupId>
<artifactId>gwt-dependencies</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-user</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.extjs</groupId>
<artifactId>gxt</artifactId>
<version>2.1.0</version>
</dependency>
<!-- etc -->
</dependencies>
</project>
These groups can then be included in your main POM.

- 10,115
- 3
- 44
- 62
-
1Also see: http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html – amit kumar Oct 21 '13 at 05:22
More recently, the option of using Maven Tiles has become possible. The plugin will allow you to perform the mixin operations not provided by Maven 3. However, each mixin requires a released tile artefact.

- 848
- 1
- 13
- 30