maven 继承和聚合

代码片段(1)[全屏查看所有代码]

1. [代码][Java]代码     跳至 [1] [全屏预览]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
一,聚合配置代码:
 
<modules>
     <module>../Hello</module> 
     <module>../HelloFriend</module>    
     <module>../MakeFriends</module>
</modules>
 
其中module的路径为相对路径。
 
 
二,继承配置代码:
 
<parent> 
         <groupId>cn.itcast.maven</groupId>
     <artifactId>Project</artifactId>
     <version> 0.0 . 1 -SNAPSHOT</version>
         <relativePath>../Project/pom.xml</relativePath> 
</parent>
 
三,继承代码过程中,可以定义属性
 
<properties>
     <project.build.sourceEncoding>UTF- 8 </project.build.sourceEncoding>
     <junit.version> 4.9 </junit.version>
     <maven.version> 0.0 . 1 -SNAPSHOT</maven.version>
</properties>
 
访问属性的方式为${junit.version},例如:
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>${junit.version}</version>
             <scope>test</scope>
         </dependency>
 
 
四,将父模块中将用dependencyManagement进行管理
 
<dependencyManagement>
     <dependencies>
     <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>${junit.version}</version>
         <scope>test</scope>
     </dependency>
     <dependency>
             <groupId>cn.itcast.maven</groupId>
             <artifactId>HelloFriend</artifactId>
             <version>${maven.version}</version>
             <type>jar</type>
             <scope>compile</scope>
      </dependency>
       
      </dependencies>
   </dependencyManagement>
 
这样的好处是子模块可以有选择行的继承,而不需要全部继承。

原文地址:http://www.oschina.net/code/snippet_1398304_35597



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值