当通过Maven创建一个组件项目中,即一个Maven工程通过多个工程组合起来。而每个工程形成一个jar包。一个总的工程需要依赖这些jar。如下面的配置:
我的site工程中包括
<modules>
<module>exambase</module>
<module>unitpoint</module>
<module>userrole</module>
<module>resourcefile</module>
<module>webexam</module>
<module>base</module>
<module>dimension</module>
<module>exam_english</module>
<module>filemanager</module>
</modules>
其中”base“、”dimension","filemanager"三个工程为基础工程不需要依赖其他工程。而"userrole"工程需要依赖“base”工程,“unitpoint”工程需要依赖“userrole”,"filemanager","base"工程,"resourceFile"需要依赖“unitpoint”,"filemanager"工程,“exambase"需要依赖”filemanager“,"userrole","unitpoint"工程,"exam-english"需要依赖"exambase"工程,而”webexam“则需要依赖其他所有的工程。
当开发,如果我将Base工程的版本进行更新,则需要将所有相关联的pom.xml文件进行修改,以采用最新的版本。
因此我们可以采用maven的(dependencyManagement)功能进行最新版本的管理。
首先我们定义版本的升级规则;如我的版本为(0.0.1-SNAPSHOT).而第做一次修改版本号+1。
这个我的配置就是
<properties>
<exam-version>[0.0.1-SNAPSHOT,]</exam-version>
</properties>
这个配置中的中括号和逗号是必须的。
然后加入下面的配置。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-base</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-dimension</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-filemanager</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-userrole</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-unitpoint</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-resourcefile</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-exambase</artifactId>
<version>${exam-version}</version>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam_english</artifactId>
<version>${exam-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
这样只需要在有相关依赖的Pom.xml文件中加入下面的配置就可以了
<dependencies>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-dimension</artifactId>
</dependency>
<dependency>
<groupId>com.sdzn</groupId>
<artifactId>exam-unitpoint</artifactId>
</dependency>
</dependencies>
由于版本我们以上通过
dependencyManagement进行管理。因此在这里只需要写上需要依赖的工程即可。