maven高级-黑马-笔记

1.分模块开发

(1) 创建Maven模块
(2) 书写模块代码
分模块开发需要先针对模块功能进行设计,再进行编码。不会先将工程开发完毕,然后进行拆分。拆分方式可以按照功能拆也可以按照模块拆。
(3)通过maven指令安装模块到本地仓库(install 指令)

2.依赖管理

依赖是具有传递性的

  • 直接依赖
  • 间接依赖

依赖冲突:

依赖冲突是指项目依赖的某一个jar包,有多个不同的版本,因而造成类包版本冲突。

  • 情况一:特殊优先:当同级配置了相同资源的不同版本,后配置的覆盖先配置的。

  • 情况二:路径优先:当依赖中出现相同的资源时,层级越深,优先级越低,层级越浅,优先级越高

  • 情况三: 声明优先:当资源在相同层级被依赖时,配置顺序靠前的覆盖配置顺序靠后的

在这里插入图片描述

可选依赖和排除依赖

方案一:可选依赖

<dependency>
<groupId>com.itheima</groupId>
<artifactId>maven_03_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
<!--可选依赖是隐藏当前工程所依赖的资源,隐藏后对应资源将不具有依赖传递-->
<optional>true</optional>
</dependency>

方案二:排除依赖

<dependency>
      <groupId>org.example</groupId>
      <artifactId>maven04</artifactId>
      <version>1.0-SNAPSHOT</version>
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  • A依赖B,B依赖C , C 通过依赖传递会被A 使用到,现在要想办法让A 不去依赖C
  • 可选依赖是在B上设置 , A不知道有C 的存在,
  • 排除依赖是在A上设置 , A 知道有C 的存在,主动将其排除掉。

3.聚合和继承

聚合

所谓聚合:将多个模块组织成一个整体,同时进行项目构建的过程称为聚合

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>maven01</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <!--设置管理的模块名称-->
    <modules>
        <module>../maven02</module>
        <module>../maven03</module>
        <module>../maven04</module>
    </modules>

</project>

继承

所谓继承:描述的是两个工程间的关系,与java中的继承相似,子工程可以继承父工程中的配置信息,常见于依赖关系的继承。

  <!--配置当前工程继承自parent工程-->
  <parent>
    <groupId>org.example</groupId>
    <artifactId>maven01</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../maven01/pom.xml</relativePath>
  </parent>
<!--定义依赖管理-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

在这里插入图片描述

3.属性

属性

<properties>
<spring.version>5.2.10.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<mybatis-spring.version>1.3.0</mybatis-spring.version>
</properties>

在这里插入图片描述

4.多环境配置与应用

多环境开发

 <!--配置多环境-->
    <profiles>
        <!--开发环境-->
        <profile>
            <id>env_dep</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.1.1.1:3306/ssm_db</jdbc.url>
            </properties>
            <!--设定是否为默认启动环境-->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!--生成环境-->
        <profile>
            <id>env_pro</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.2.2.2:3306/ssm_db</jdbc.url>
            </properties>
        </profile>
        <!--测试环境-->
        <profile>
            <id>env_test</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.3.3.3:3306/ssm_db</jdbc.url>
            </properties>
        </profile>
    </profiles>

跳过测试

			<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <!--排除掉不参与测试的内容-->
                    <excludes>
                        <exclude>**/BookServiceTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
  • 使用Maven的命令行, mvn 指令 -D skipTests

5.私服

在这里插入图片描述

<distributionManagement>
        <repository>
            <id>itheima-release</id>
            <url>http://localhost:8081/repository/itheima-release/</url>
        </repository>
        <snapshotRepository>
            <id>itheima-snapshot</id>
            <url>http://localhost:8081/repository/itheima-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值