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 3.3.0.ga
, 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 ...
Get Maven: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.