Maven项目之间的关系

1. 依赖关系

  1.1 标签<dependency>把另一个项目的jar引入到当前项目

  1.2 自动下载另一个项目所依赖的其他项目

2. 继承关系.

  2.1 父项目是pom类型

  2.2 子项目jar或war,如果子项目还是其他项目的父项目,子项目也是pom类型.

  2.3 有继承关系后,子项目中出现<parent>标签

    2.3.1 如果子项目的<groupId>和<version>与父项目项目,在子项目中可以不配置<groupId>和<version>

  2.4 父项目pom.xml中是看不到有哪些子项目.在逻辑上具有父子项目关系.

    <parent>

      <groupId>com.bjsxt</groupId>

      <artifactId>parent</artifactId>

      <version>0.0.1-SNAPSHOT</version>

    </parent>

3. 聚合关系.

  3.1 前提是继承关系.父项目会把子项目包含到父项目中.

  3.2 子项目的类型必须是Maven Module而不是maven project

  3.3 新建聚合项目的子项目时,点击父项目右键新建Maven Module

  3.4 具有聚合关系的父项目,在pom.xml中<modules>

  <modules>

    <module>child2</module>

    </modules>

  3.5 具有聚合关系的子项目,在pom.xml中<parent>

  <parent>

      <groupId>com.bjsxt</groupId>

      <artifactId>parent</artifactId>

      <version>0.0.1-SNAPSHOT</version>

    </parent>

4. 聚合项目和继承项目区别

  4.1 在语意上聚合项目父项目和子项目关系性较强

  4.2 在语意上单纯继承项目父项目和子项目关系性较弱

5. <dependencyManagement> 写在父项目

  5.1 作用:声明可能使用到的所有jar

  5.2 子项目中只需要有坐标的<groupid>和<artifactid>,<version>继承父项目

  5.3 在父项目中<properties>把所有版本好进行统一管理

  5.4 父项目pom.xml

    5.4.1 <properties>子标签名称自定义

    5.4.2 ${名字} 引用标签的值

   <properties>

      <spring-version>4.1.6.RELEASE</spring-version>

   </properties>

   <dependencyManagement>

      <dependencies>

         <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-webmvc</artifactId>

            <version>${spring-version}</version>

         </dependency>

      </dependencies>

   </dependencyManagement>

5.5 子项目

   <dependencies>

      <dependency>

         <groupId>org.springframework</groupId>

         <artifactId>spring-webmvc</artifactId>

      </dependency>

   </dependencies>

原文地址:https://www.cnblogs.com/hwgok/p/10055342.html