zoukankan      html  css  js  c++  java
  • maven学习(十一)——maven中的聚合与继承

    一、聚合

      如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合

    1.1、聚合配置代码

    <modules>
           <module>模块一</module>
           <module>模块二</module>
           <module>模块三</module>
    </modules>

    例如:对项目的Hello、HelloFriend、MakeFriends这三个模块进行聚合

    <modules>
           <module>../Hello</module>  
           <module>../HelloFriend</module>        
           <module>../MakeFriends</module>
    </modules>

    其中module的路径为相对路径。

    二、继承

      继承为了消除重复,我们把很多相同的配置提取出来,例如:grouptId,version等

    2.1、继承配置代码

    <parent>  
              <groupId>me.gacl.maven</groupId>
              <artifactId>ParentProject</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <relativePath>../ParentProject/pom.xml</relativePath>  
    </parent>

    2.2、继承代码中定义属性

      继承代码过程中,可以定义属性,例如:

    <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>    

    2.3、父模块用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>

    这样的好处是子模块可以有选择行的继承,而不需要全部继承。

    三、聚合与继承的关系

      聚合主要为了快速构建项目,继承主要为了消除重复。

  • 相关阅读:
    read()系统调用的流程(转个贴)
    linux kernel reading
    开博第一篇
    让人崩溃的Visual C++ 2005 SP1 Redistributable Package (x86),为啥我下不下来?
    System Call on Linux 2.6 for i386(2) int 0x80与systementer
    http://www.netyi.net/in.asp?id=yuanxianping
    取Insert产生的ID
    递归触发器资料
    Commit Trans和Rollback Trans在有触发器操作时的区别
    转:安全配置SQL Server2000服务器
  • 原文地址:https://www.cnblogs.com/jack1208-rose0203/p/6298088.html
Copyright © 2011-2022 走看看