You are previewing Maven: The Definitive Guide.

Maven: The Definitive Guide

Cover of Maven: The Definitive Guide by Sonatype Company Published by O'Reilly Media, Inc.

Optimizing Dependencies

If you look through the various POMs created in Chapter 7, note several patterns of replication. The first pattern we can see is that some dependencies such as spring and hibernate-annotations are declared in several modules. The hibernate dependency also has the exclusion on javax.transaction replicated in each definition. The second pattern of duplication to note is that sometimes several dependencies are related and share the same version. This is often the case when a project’s release consists of several closely coupled components. For example, look at the dependencies on hibernate-annotations and hibernate-commons-annotations. Both are listed as version, and we can expect the versions of both these dependencies to change together going forward. Both the hibernate-annotations and hibernate-commons-annotations are components of the same project released by JBoss, and so when there is a new project release, both of these dependencies will change. The third and last pattern of duplication is the duplication of sibling module dependencies and sibling module versions. Maven provides simple mechanisms that let you factor all of this duplication into a parent POM.

Just as in your project’s source code, any time you have duplication in your POMs, you open the door a bit for trouble down the road. Duplicated dependency declarations make it difficult to ensure consistent versions across a large project. When you only have two or three modules, this might ...

The best content for your career. Discover unlimited learning on demand for around $1/day.