zoukankan      html  css  js  c++  java
  • springboot依赖管理

    问题引入:

    springboot工程A依赖工程B, B中定义 jackson 的依赖版本为 2.11.2, 在A中除去[spring-boot-starter-web:2.1.3.RELEASE]对 jackson 的依赖. 查看工程A依赖的 jsckson 版本, 结果是:2.9.8

    这是为什么呢? 答案要从 springboot 依赖管理探寻. 我们知道一个 sptingboot 工程的 pom 文件都有如下配置:

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.3.RELEASE</version>
            <relativePath/>
        </parent>

    查看 spring-boot-starter-parent-2.1.3.RELEASE.pom, 它又继承于 spring-boot-dependencies

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.3.RELEASE</version>
            <relativePath>../../spring-boot-dependencies</relativePath>
        </parent>
        ...

    查看 spring-boot-dependencies-2.1.3.RELEASE.pom

        <properties>
            ...
            <jackson.version>2.9.8</jackson.version>
            ...
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot</artifactId>
                    <version>2.1.3.RELEASE</version>
                </dependency>
                ...
            </dependencies>
        </dependencyManagement>

    看到这里, 答案似乎跃然纸上了. 是 springboot 工程A继承了 spring-boot-dependencies 的 pom 文件中的 properties, 导致覆盖了从B工程依赖的 jackson 版本.

    再进一步思考,如果我想升级 springboot 的 jackson 版本该怎么做呢? 答案很简单, 只需要在 springboot 工程 pom 文件的 properties 标签下增加如下代码:

    <jackson.version>2.11.2</jackson.version>

    彩蛋:

    relativePath 标签

    The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories.
    Default value is: ../pom.xml.

    http://maven.apache.org/ref/3.0/maven-model/maven.html

    Inheritance 继承, 阐述了 children 可以继承哪些 parent POM elements

    Most elements from the parent POM are inherited by its children, including: properties...
    https://maven.apache.org/pom.html#Inheritance

  • 相关阅读:
    redis 笔记
    经验
    增加模块-概念图
    node API buffer
    VS2010中使用CL快速 生成DLL的方法
    WIN7下VS2010中使用cl编译的步骤
    Win7下VS2010编译的程序在XP报错:找不到msvcp100d.dll或者msvcp100.dll
    C#速学
    Windows下架设SVN服务
    Redis 压力测试
  • 原文地址:https://www.cnblogs.com/xxoome/p/13731573.html
Copyright © 2011-2022 走看看