一篇好文章,必须分享:http://www.infoq.com/cn/news/2011/01/xxb-maven-3-pom-refactoring,博主文章不错,可看看。
我看了看maven官网关于import scope 方式的例子:http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies
之前说的pluginManagement元素是用来统一管理子项目依赖。而今天看到了一篇,不用继承的方式,子项目jar版本同样可以被统一管理。
以下根据maven官网例子
1、目录结构如图:
2、然后在任意目录下,新建一个maven project,pom.xml 如下:
<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.test</groupId>
<artifactId>use</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>bom</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>project1</artifactId>
</dependency>
<dependency>
<groupId>com.test</groupId>
<artifactId>project2</artifactId>
</dependency>
</dependencies>
</project>
执行mvn help:effective-pom,可以看到其原型。如我上面paste的pom.xml 它确实没有使用继承,但是,同样可以进行版本统一控制。
完!