maven的继承与聚合(maven8)

一、继承

    ①情景

    Helloy依赖Junit:4.0

    HelloFriend依赖Junit:4.0

    MakeFriends依赖Junit:4.9

    ②原有

    由于test范围的依赖不能传递,所以很容易造成版本不一致

    ③需求:统一管理各个模块工程中对Junit的 依赖版本

    ④解决思路:将Junit  依赖的版本统一提取到“父”工程中,在“子”工程中声明Junit依赖是不指定版本,已“父”

    工程设定的版本Wie准,同时也便于修改

    ⑤操作步骤

        【1】创建一个Maven工程作为父工程,注意:打包的方式为pom

<modelVersion>4.0.0</modelVersion>
<groupId>com.montnets.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

      【2】在子工程中声明对父工程的依赖

<!--声明父工程  -->
     <parent>
          <groupId>com.montnets.maven</groupId>
          <artifactId>Parent</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <!--relativePath以当前工程pom.xml为基准的父工程的pom,xml的 相对路径 -->
          <relativePath>../Parent/pom.xml</relativePath>
     </parent>

     【3】将子工程的坐标中与父工程的坐标中重复内容删除重复部分

 

    删除重复部分,也可以不删除

  【4】在父工程中统一管理Junit的依赖

<!--配置依赖管理  -->
     <dependencyManagement>
          <dependencies>
               <dependency>
                   <groupId>junit</groupId>
                   <artifactId>junit</artifactId>
                   <version>4.0</version>
                   <scope>test</scope>
               </dependency>
          </dependencies>
     </dependencyManagement>

   【5】在子工程中删除Junit依赖的版本号部分 

【6】子工程配置了父工程,执行安装要先安装工程

二、聚合

    ①作用:一键安装各个模块工程

    ②配置方式:在一个”总的聚合工程”中配置各个参与聚合的模块

 <!--配置聚合  -->
  <modules>
     <module>../Hello</module>
     <module>../HelloFriend</module>
     <module>../MakeFriends</module>
  </modules>

③使用方式:在聚合的工程pom.xml上点击右键——>run as——>maven install

三、web工程自动化部署

<!-- build配置当前工程中的特殊设置 -->
  <build>
          <!--finalName工程的最终名字  -->
          <finalName>MontnetsWeb</finalName>
          <!-- plugins配置过程中需要使用的插件 -->
          <plugins>
              <plugin>
                   <!-- 插件坐标,cargo专门从事“启动Servlet容器” 的组织-->
                   <groupId>org.codehaus.cargo</groupId>
                   <artifactId>cargo-maven2-plugin</artifactId>
                   <version>1.2.3</version>
                   <!--configuration 针对插件进行的配置 -->
                   <configuration>
                        <!-- container配置当前系统中容器的位置 -->
                        <container>
                             <!--containerId tomcat版本  -->
                             <containerId>tomcat7x</containerId>
                             <home>D:\apache-tomcat-7.0.30</home>
                        </container>
                        <configuration>
                             <type>existing</type>
                             <!-- 确认当前系统容器的位置 -->
                             <home>D:\apache-tomcat-7.0.30</home>
                             <!-- 如果Tomcat端口为默认值8080则不必设置该属性 -->
                             <!-- <properties>
                                  <cargo.servlet.port>8989</cargo.servlet.port>
                             </properties> -->
                        </configuration>
                   </configuration>
                   <!-- executions配置插件在什么情况下执行 -->
                   <executions> 
                        <execution> 
                             <id>cargo-run</id> 
                             <!--生命周期的阶段  -->
                             <phase>install</phase> 
                             <goals> 
                                  <!--goals 插件的目标 -->
                                  <goal>run</goal> 
                             </goals> 
                        </execution> 
                   </executions>
              </plugin>
          </plugins>
     </build>

eclipse按停掉server按钮,端口还是占用,需要进入tomcat的bin目录shutdown

查找依赖信息网站

http://mvnrepository.com/

以上通过结合谷粒学院maven学习视频所记录的笔记

谷粒学院学习官网:http://www.gulixueyuan.com

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值