如果我们看一下不同的插件配置,就能看到HSQLDB依赖在很多地方有重复。不幸的是,dependencyManagement不适用于插件依赖,但我们仍然可以使用属性来巩固版本。大部分复杂的Maven多模块项目倾向于在顶层POM中定义所有的版本。这个顶层POM就成了影响整个项目的更改焦点。将版本号看成是Java类中的字符串字面量,如果你经常重复一个字面量,你可能会将它定义为一个变量,当它需要变化的时候,你就只需要在一个地方更改它。将HSQLDB的版本集中到顶层的POM中,就产生了如下的属性元素。
<project>
...
<properties>
<hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version>
<hsqldb.version>1.8.0.7</hsqldb.version>
</properties>
...
</project>下一件我们要注意的事情是hibernate3-maven-plugin配置在simple-webapp和simple-command模块中重复了。我们可以在顶层POM中管理这个插件配置,就像我们在顶层POM中使用dependencyManagement片段管理依赖一样。为此,我们要使用元素顶层POM
build元素下的pluginManagement元素。
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
</configuration>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>

