maven 继承和聚合

来源:互联网 发布:淘宝处罚条例 编辑:程序博客网 时间:2024/05/18 01:11

代码片段(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



0 0
原创粉丝点击