码迷,mamicode.com
首页 > 其他好文 > 详细

maven 继承关系和聚合

时间:2014-07-06 14:35:03      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   

maven继承管理 让版本的管理只在一个地方改变

 

modules用于聚合,把执行的项目都放到同一的地方用module包括,可以省去一个个项目去mvn install,这样可以所有项目一次聚合 mvn install

传递性依赖原则:

A-->B
A-->C

1.路径最近者优先
2.路径相同,第一声明者优先

注意:
1.dependencyManagement中定义的依赖子module不会共享
2.dependencies中定义的依赖子module可以共享

 

dependencyManagement的使用 就是方便管理版本,子项目中要引入group id和atifact id

 

在parent项目的pom.xml配置

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 3   <modelVersion>4.0.0</modelVersion>
 4 
 5   <groupId>cn.itcast.maven</groupId>
 6   <artifactId>Parent</artifactId>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <packaging>pom</packaging>
 9 
10   <name>Parent</name>
11   <url>http://maven.apache.org</url>
12 <!--聚合-->
13   <modules>
14       <module>../Hello</module>  
15       <module>../HelloFriend</module>        
16       <module>../MakeFriends</module>
17       <module>../Web</module>
18 </modules>
19 
20   <properties>
21     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22   </properties>
23 
24 <!--定义了依赖的关系,让其他项目继承这些包,不用写版本,同一控制了-->
25   <dependencyManagement>
26   
27 
28   <dependencies>
29     <dependency>
30       <groupId>junit</groupId>
31       <artifactId>junit</artifactId>
32       <version>4.9</version>
33       <scope>test</scope>
34     </dependency>
35     <dependency>
36             <groupId>cn.itcast.maven</groupId>
37             <artifactId>Hello</artifactId>
38             <version>0.0.1-SNAPSHOT</version>
39             <scope>compile</scope>
40         </dependency>
41     <dependency>
42       <groupId>cn.itcast.maven</groupId>
43       <artifactId>HelloFriend</artifactId>
44       <version>0.0.1-SNAPSHOT</version>
45     </dependency>
46     <dependency>
47       <groupId>cn.itcast.maven</groupId>
48       <artifactId>MakeFriends</artifactId>
49       <version>0.0.1-SNAPSHOT</version>
50     </dependency>
51   </dependencies>
52   </dependencyManagement>
53   
54  <distributionManagement> 
55     <repository> 
56         <id>releases</id> 
57         <name>Internal Releases</name> 
58         <url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url> 
59     </repository> 
60     <snapshotRepository> 
61         <id>snapshots</id> 
62         <name>Internal Snapshots</name> 
63         <url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url> 
64     </snapshotRepository> 
65   </distributionManagement>
66  
67   
68 </project>

 

Hello.pom

 1 <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">
 2   <modelVersion>4.0.0</modelVersion>
 3   
 4   <artifactId>Hello</artifactId>
 5   
 6 
 7   <parent>  
 8           <groupId>cn.itcast.maven</groupId>
 9      <artifactId>Parent</artifactId>
10       <version>0.0.1-SNAPSHOT</version>
11         <relativePath>../Parent/pom.xml</relativePath>  
12 </parent>
13 <dependencies>
14 <!--不用写版本了  parent那里同一控制了-->
15     <dependency>
16             <groupId>junit</groupId>
17             <artifactId>junit</artifactId>
18         </dependency>
19 </dependencies>
20 
21 </project>

HelloFriend  pom.xml

 1 <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">
 2   <modelVersion>4.0.0</modelVersion>
 3   
 4   <artifactId>HelloFriend</artifactId>
 5   
 6   <name>HelloFriend</name>
 7   
 8     <parent>  
 9           <groupId>cn.itcast.maven</groupId>
10      <artifactId>Parent</artifactId>
11       <version>0.0.1-SNAPSHOT</version>
12         <relativePath>../Parent/pom.xml</relativePath>  
13   </parent>
14   <dependencies>
15     <dependency>
16       <groupId>junit</groupId>
17       <artifactId>junit</artifactId>
18     </dependency>
19     <dependency>
20             <groupId>cn.itcast.maven</groupId>
21             <artifactId>Hello</artifactId>
22     </dependency>
23     </dependencies>
24 </project>

 

maven 继承关系和聚合,布布扣,bubuko.com

maven 继承关系和聚合

标签:style   blog   http   color   使用   os   

原文地址:http://www.cnblogs.com/friends-wf/p/3825641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!