maven课程 项目管理利器-maven 3-10 maven聚合和继承 4星

本节主要讲了以下内容:

1    maven聚合

2    maven继承

1    maven聚合

<!--  聚合特有标签 -->
  <groupId>com.hongxing</groupId>
  <artifactId>hongxing-juhe</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  
  
  <modules>
   <module>../hongxing-bige</module>
   <module>../hongxing-nange</module>
   <module>../hongxing-sanji</module>
  </modules>

2    maven继承

hongxing-parent父类项目做了四个操作

a  pom.xml中package标签变为pom,

b  junit version被提取,引用的地方用el表达式表示

c  pom.xml引入junit

d    hongxing-parent项目删除src和test文件夹(因为package标签为pom的项目不编译,该两个文件夹中引用junit注解的地方会报错,故删除)

<!--   此处添加继承,把junit 让hongxing其他项目继承 -->
  <properties>
    <junitVersion>4.11</junitVersion>
    
  </properties>


  <dependencyManagement>
      <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junitVersion}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  </dependencyManagement>

子项目hongxing-bige需要做两个操作即可

a  继承父项目

b  把子项目的版本号和依赖范围去除即可

<!-- b哥去掉version和scope标签,继承hongxing-parent项目 -->

  <parent>
        <groupId>com.hongxing</groupId>
        <artifactId>hongxing-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
  </dependencies>
原文地址:https://www.cnblogs.com/1446358788-qq/p/9907119.html