1. 作用:通过继承可以实现在子工程中沿用父工程的配置。
    1. maven中的继承与java中的继承相似,在子配置中配置继承关系。
  2. 制作关系:
    1. 在子工程中声明其父工程坐标与对应的位置:
      1
      2
      3
      4
      5
      6
      7
      8
      <!-- -->
      <parent>
      <groupId>com.itheima</groupId>
      <artifactId>ssm</artifactId>
      <version>1.0-SNAPSHOT</version>
      <!-- pom -->
      <relativePath>../ssm/pom.xml</relativePath>
      </parent>

继承依赖定义

  • 在父工程中定义依赖管理:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <!-- -->
    <dependencyManagement>
    <!-- -->
    <dependencies>
    <!--spring -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.1.9.RELEASE</version>
    </dependency>
    </dependencies>
    </dependencyManagement>

继承依赖使用

  • 在子工程中定义依赖关系,无需声明依赖版本,版本参照工程中依赖的版本。
    1
    2
    3
    4
    5
    6
    7
    <dependencies>
    <!--spring -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    </dependency>
    </dependencies>

继承的资源

  • groupld:项目组ID,项目坐标的核心元素
  • ciManagement:项目的持续集成系统信息
  • version:项目版本,项目坐标的核心因素
  • scm:项目的版本控制系统西溪
  • description:项目的描述信息
  • malilingLists:项目的邮件列表信息
  • organization:项目的组织信息
  • properties:.自定义的Maven属性
  • inceptionYear:项目的创始年份
  • dependencies:项目的依赖配置
  • url:项目的URL地址
  • dependencyManagement:项目的依赖管理配置
  • developers:项目的开发者信息
  • repositories:项目的仓库配置
  • contributors:项目的贡献者信息
  • buld:包括项目的源码目录配置、输出目录配置、插件配置、
  • distributionManagement:项目的部署配置、插件管理配置等
  • issueManagement:项日的缺陷跟踪系统信息
  • reporting:包括项日的报告输出日录配置、报告插件配置等

继承与聚合

  • 作用:
    • 聚合用于快速构建项目
    • 继承用于快速配置
  • 相同点:
    • 聚合与继承的pom.xml文件打包方式均为pom,可以将两种关系制作到同一个pom文件中。
    • 聚合与继承均属于设计型模块,并无实际的模块内容。
  • 不同点:
    • 聚合是在当前模块中配置关系,聚合可以感知到参与聚合的模块有哪些。
    • 继承是在子模块中配置关系,父模块并无法感知哪些子模块继承了自己。

小结

  • 继承的作用
  • 继承的内容
  • 依赖继承
    • 定义在父工程中
    • 使用在子工程中(无需配置version)