dependencyManagement
Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式。通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素。使用pom.xml 中的dependencyManagement 元素能让
所有在子项目中引用一个依赖而不用显式的列出版本号。Maven 会沿着父子层次向上走,直到找到一个拥有dependencyManagement 元素的项目,然后它就会使用在这个dependencyManagement 元素中指定的版本号。dependencyManagement里只是声明依赖,并不实现引入dependencies中申明的jar包到classpath中,因此子项目需要显式的声明需要用的依赖.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gp</groupId>
<artifactId>test</artifactId>
<version>framework-develop</version>
<packaging>pom</packaging>
<description>定义公共信息及依赖版本管理</description>
<modules>
<module>core</module>
<module>dao</module>
<module>service</module>
<module>example</module>
<module>search</module>
</modules>
<properties>
<url.nexus.server>http://123.57.51.101:8081</url.nexus.server>
<!--test -->
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
</properties>
<dependencies>
<!--test 此处为引入,并默认被所有的子项目继承,可以不指定版本号-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!--test 此处只申明不引入-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!--分发构件至远程仓库-->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>${url.nexus.prefix}/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>${url.nexus.prefix}/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>