maven継承関係と集約

27047 ワード

maven継承管理バージョンの管理を1つの場所でのみ変更
 
modules    ,               module  ,          mvn install,             mvn install

伝達依存の原則:
A-->BA-->C
1.経路最近接者優先2.パスが同じで、第1の宣言者が優先されます.
注意:1.dependencyManagementで定義された依存子moduleは共有しません.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>