Optimizing Plugins
If we take a look at the various plugin configurations, we can
see the HSQLDB dependencies duplicated
in several places. Unfortunately,
dependencyManagement
doesnât apply to plugin
dependencies, but we can still use a property to consolidate the
versions. Most complex Maven multimodule projects tend to define all
versions in the top-level POM. This top-level
POM then becomes a focal point for changes that
affect the entire project. Think of version numbers as string literals
in a Java class; if you are constantly repeating a literal, youâll
likely want to make it a variable so that when it needs to be changed,
you have to change it in only one place. Rolling up the version of
HSQLDB into a property in the top-level
POM yields the following properties
element:
<project> ... <properties> <hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version> <hsqldb.version>1.8.0.7</hsqldb.version> </properties> ... </project>
The next thing we notice is that the
hibernate3-maven-plugin
configuration is duplicated
in the simple-webapp
and
simple-command
modules. We can manage the plugin
configuration in the top-level POM just as we
managed the dependencies in the top-level POM with
the dependencyManagement
section. To do this, we
use the pluginManagement
element in the
top-level POMâs build
element:
<project> ... <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> ...
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.