springboot依赖管理

摘要:
弹簧防尘套启动器父级</版本>弹簧启动依赖项<../../弹簧引导依赖性<2.9.8<org.springframework.boot<弹簧套<版本>&书信电报;2.11.2<

问题引入:

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

免责声明:文章转载自《springboot依赖管理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【官方活动】亲,咱简历上的精通‘微服务’您真的懂吗? 奉送21天实战微服务免费课程oracle 内置函数(一)数值函数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

CSS3常见动画

一、是什么 CSS动画(CSS Animations)是为层叠样式表建议的允许可扩展标记语言(XML)元素使用CSS的动画的模块 即指元素从一种样式逐渐过渡为另一种样式的过程 常见的动画效果有很多,如平移、旋转、缩放等等,复杂动画则是多个简单动画的组合 css实现动画的方式,有如下几种: transition 实现渐变动画 transform 转变动画...

Altera FFT核使用详解

简介 快速傅里叶变换(Fast Fourier Transform)最为一种高效的算法,被广泛的用于信号处理与数据分析等领域。对于设计工程师来讲,自己动手采样可编程语言来实现一个FFT/IFFT模块,不知要花费多少心血。所幸的是Altera和Xilinx两大巨头都提供了自己FFT核,本文将详细讲解如何使用Altera的FFT核。 Altera FFT...

Dijkstra和堆优化

Dijkstra算法 由于我之前一直记的迪杰斯特拉的翻译导致我把dijkstra写成了dijstra……所以下文#define dijstra dijkstra 我以后叫她迪杰克斯歘! Dijskra是用来在有向图或者无向图中寻找任意两个点的最小距离的算法。它相较于spfa不会死掉(spfa死了),但是无法处理带负环的图和求最长路(除非加上一些奇怪的东西,...

layui开关遇见的坑以及用法总结

1.先看官方文档: 官方效果: 注意:如果你直接把文档中这块代码粘贴过去是不会有效果的,如果问为什么,下面是原因: 说的很清楚了,必须有form进行渲染,也就是要放到form中,当然别忘了引入一套layui,下面代码才可以正常显示 <form class="layui-form"> <div class="layui-form-i...

JS--微信浏览器复制到剪贴板实现

由于太忙很久没写博客了,如有错误遗漏,请指出,感谢! 首先这里要注意,是微信浏览器下的解决方案,其他浏览器请自行测试。 先说复制到剪贴板主要有什么使用场景: 优惠券优惠码,需要用户复制 淘宝商品,需要复制淘口令 由于淘宝链接无法在微信中打开,所以淘宝开发了淘口令方便物质传播,而导购网站在微信推广的时候也是生成口令,用户只需要复制口令,打开手机淘宝,即可...

【转】adb命令详细介绍

一. 基本简介 adb,即Android Debug Bridge,它是Android开发/测试人员不可替代的强大工具 二. 设备连接管理 1) USB连接 通过 USB 连接来正常使用 adb 需要保证几点: 硬件状态正常。 包括 Android 设备处于正常开机状态,USB 连接线和各种接口完好。 Android 设备的开发者选项和 USB...