IDEA版SSM入门到实战(Maven+MyBatis+Spring+SpringMVC) -Maven依赖管理,版本号管理,继承和聚合

第一章 Maven的依赖管理

1.1 依赖范围
  • 依赖语法:
    • compile【默认值】:在main、test、Tomcat【服务器】下均有效。
    • test:只能在test目录下有效
      • junit
    • provided:在main、test下均有效,Tomcat【服务器】无效。
      • servlet-api
1.2 依赖传递性
  • 路径最短者有先【就近原则】

  • 先声明者优先

  • 注意:Maven可以自动解决jar包之间的依赖问题

第二章 Maven中统一管理版本号

  • 语法

    <properties>
        <spring-version>5.3.17spring-version>
    properties>
    <dependencies>
        <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-beansartifactId>
                <version>${spring-version}version>
        dependency>
    dependencies>
    

第三章 Maven的继承

3.1 为什么需要继承
  • 如子工程大部分都共同使用jar包,可以提取父工程中,使用【继承原理】在子工程中使用
  • 父工程打包方式,必须是pom方式
3.2 Maven继承方式一
  • 在父工程中的pom.xml中导入jar包,在子工程中统一使用。【所有子工程强制引入父工程jar包】

  • 示例代码

    <packaging>pompackaging>
    <dependencies>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
                <version>4.12version>
                <scope>testscope>
            dependency>
        dependencies>
    
3.3 Maven继承方式二
  • 在父工程中导入jar包【pom.xml】

    <packaging>pompackaging>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
                <version>4.12version>
                <scope>testscope>
            dependency>
        dependencies>
    dependencyManagement>
    
  • 在子工程引入父工程的相关jar包

    <parent>
        <artifactId>maven_demoartifactId>
        <groupId>com.atguigugroupId>
        <version>1.0-SNAPSHOTversion>
        <relativePath>../pom.xmlrelativePath>
    parent>
     <dependencies>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
            dependency>
    dependencies>
    
  • 注意:在子工程中,不能指定版本号

第四章 Maven的聚合

  • 为什么使用Maven的聚合

    • 优势:只要将子工程聚合到父工程中,就可以实现效果:安装或清除父工程时,子工程会进行同步操作。
    • 注意:Maven会按照依赖顺序自动安装子工程
  • 语法

    <modules>
        <module>maven_helloworldmodule>
        <module>HelloFriendmodule>
        <module>MakeFriendmodule>
    modules>
    

你可能感兴趣的:(intellij-idea,maven,mybatis)