• Maven依赖仲裁


    一、影响依赖的因素

    影响依赖的标签都有哪些

    1. 直接引入具体的依赖信息。注意是不在标签内的情况。如果是在内的情况,请参考2号标签。
    2. 只声明但不发生实际引入,作为依赖管理。依赖管理是指真正发生依赖的时候,再去参考依赖管理的数据。
      这样使用dependency的时候,可以缺省version。
      另外 还可以管控所有的间接依赖,即使间接依赖声明了version,也要被覆盖掉。
    3. 声明自己的父亲,Maven的继承哲学跟Java很类似,因为Maven本身也是用Java实现的,满足单继承。
      一旦子pom继承了父pom,那么会把父pom里的 ,等等属性都继承过来的。当然如果在继承的过程中,出现一样的元素,也是子去覆盖父亲,和Java类似。
      继承时,会分类继承。dependencies继承dependencies,dependencyManagement里的依赖管理只能继承dependencyManagement范围内的依赖管理。
      每一个pom文件都会有一个父亲,即使不声明Parent,也会默认有一个父亲。和Java的Object设计哲学类似。后面在源码分析中我们还会提到。
    4. 代表当前自己的项目的一个属性的集合。
      properties仅仅代表属性的声明,一个属性声明了,和他是否被引用并无关系。我完全可以声明一系列不被人使用的属性。

    依赖的作用域都有哪些

    一个依赖在引入的时候,是可以声明这个依赖的作用范围的。比如这个依赖只对本地起作用,比如只对测试起作用等等。作用域一共有compile,provided,system,test,import,runtime 这几个值。

    简单总结一下:

    • compile和runtime会参与最后的打包环节,其余的都不会。compile可以不写。
    • test只会对 src/test目录下的测试代码起作用。
    • provided是指线上已经提供了这个Jar包,打包的时候不需要在考虑他了,一般像serlvet的包很多都是provided。
    • system和provided没什么太大的区别。
    • import只会出现在dependencyManagement标签内的依赖中,是为了解决Maven的单继承。引入了这个作用域的话,maven会把此依赖的所有的dependencyManagement内的元素加载到当前pom中的,但不会引入当前节点。如下图,并不会引入fastjson作为依赖管理的元素,只是会把fastjson文件定义的依赖管理引入进来。
    <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.24</version>
        <scope>import</scope>
      </dependency>
    <dependencies>
    <dependencyManagement>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    二、单个Jar包内的依赖竞争

    Maven仲裁机制原则

    1. 依赖竞争时,越靠近主干的越优先。
    2. 单颗树在依赖在竞争时(dependencies)(注意:不是dependencyManagement里的dependencies):
      当deep=1,即直接依赖。同级是靠后优先。
      当deep>1,即间接依赖。同级是靠前优先。

      无论直接依赖还是间接依赖,同级都是靠前优先
    3. 单颗树在依赖管理在竞争时(注意:是dependencyManagement里的dependencies)是靠前优先的。
    4. maven里最重要的2个关系,分别是继承关系和依赖关系。我们所有的规律都应该只从这2个关系入手。

    提炼几点通俗易懂的解释如下

    依赖传递原则

    当在Maven项目中引入A的依赖,A的依赖通常又会引入B的jar包,B可能还会引入C的jar包。这样,当你在pom.xml文件中添加了A的依赖,Maven会自动的帮你把所有相关的依赖都添加进来。
    比如,在Spring Boot项中,当引入了spring-boot-starter-web:

    org.springframework.boot
    spring-boot-starter-web

    我们就可以理解为依赖的传递性。即当一个依赖需要另外一个依赖支撑时,Maven会帮我们把相应的依赖依次添加到项目当中。
    这样的好处是,使用起来就非常方便,不用自己挨个去找依赖Jar包了。坏处是会引起Jar包冲突,我们后面会讲到。

    最短路径优先原则

    依赖链路一:主要根据依赖的路径长短来决定引入哪个依赖(两个冲突的依赖)。
    举例说明:
    依赖链路一:A -> X -> Y -> Z(21.0)
    依赖链路二:B -> Q -> Z(20.0)
    项目中同时引入了A和B两个依赖,它们间接都引入了Z依赖,但由于B的依赖链路比较短,因此最终生效的是Z(20.0)版本。这就是最短路径优先原则。

    最先声明优先原则

    如果两个依赖的路径一样,最短路径优先原则是无法进行判断的,此时需要使用最先声明优先原则,也就是说,谁的声明在前则优先选择。
    举例说明:
    依赖链路一:A -> X -> Z(21.0)
    依赖链路二:B -> Q -> Z(20.0)
    A和B最终都依赖Z,此时A的声明(pom中引入的顺序)优先于B,则针对冲突的Z会优先引入Z(21.0)。

    三. springboot合并打包策略

    多棵树构建顺序原则
    这个功能在Maven的源码中是一个叫Reactor(反应堆)实现的。它主要做了一件事情就是决定一个项目中,多个子pom谁先进行build的顺序,这个出厂顺序很重要,在合并打包时,往往决定了最终谁会在多个pom之间胜出的问题。
    Reactor的原则
    多棵树(多个子pom)构建的顺序是按照被依赖方的要在前,依赖方在后的原则。
    项目要保证这里是不能出现循环依赖的。

    Reactor的原则图解
    如下图子pom1 在被子pom2和子pom3同时依赖,所以子pom1最先被构建,子pom3没有人被依赖,所以最后构建。

    springboot打包策略
    springboot打包会打成一个Fatjar,所有的依赖都会放在BOOT-INF/lib/目录下。
    springboot的打包是越靠后的构建pom越优先,是一种覆盖思想。

    springboot对应的打包插件:

    org.springframework.boot
    spring-boot-maven-plugin

    springboot对应的打包插件代码库:
    https://github.com/spring-projects/spring-boot/tree/main/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin

    对应的打包插件知识库:
    https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/

    在项目中调试的话需要在dependencies节点中引入:

    org.springframework.boot
    spring-boot-maven-plugin

    测试工程:
    https://github.com/lzc-alioo/springbootmvndemo

    一次完整依赖分析(通过命令mvn dependency:tree -Dverbose可以查看仲裁说明):

     ~/work/gitstudy/springbootmvndemo  mvn dependency:tree -Dverbose
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Build Order:
    [INFO]
    [INFO] springbootmvndemo                                                  [pom]
    [INFO] module1                                                            [jar]
    [INFO] module2                                                            [jar]
    [INFO] start                                                              [jar]
    [INFO]
    [INFO] -------------------< com.example:springbootmvndemo >--------------------
    [INFO] Building springbootmvndemo 0.0.1-SNAPSHOT                          [1/4]
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] --- maven-dependency-plugin:3.3.0:tree (default-cli) @ springbootmvndemo ---
    [INFO] com.example:springbootmvndemo:pom:0.0.1-SNAPSHOT
    [INFO]
    [INFO] ------------------------< com.example:module1 >-------------------------
    [INFO] Building module1 0.0.1-SNAPSHOT                                    [2/4]
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-dependency-plugin:3.3.0:tree (default-cli) @ module1 ---
    [INFO] com.example:module1:jar:0.0.1-SNAPSHOT
    [INFO] \- com.alibaba:fastjson:jar:1.2.46:compile
    [INFO]    +- com.squareup.retrofit2:retrofit:jar:2.1.0:provided
    [INFO]    |  \- (com.squareup.okhttp3:okhttp:jar:4.9.3:provided - version managed from 3.3.0; omitted for duplicate)
    [INFO]    +- com.squareup.okhttp3:okhttp:jar:4.9.3:provided (version managed from 3.6.0)
    [INFO]    |  +- com.squareup.okio:okio:jar:2.8.0:provided
    [INFO]    |  |  +- (org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided - version managed from 1.4.0; omitted for duplicate)
    [INFO]    |  |  \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided (version managed from 1.4.0)
    [INFO]    |  \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided (version managed from 1.4.10)
    [INFO]    |     +- (org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided - version managed from 1.6.21; omitted for duplicate)
    [INFO]    |     \- org.jetbrains:annotations:jar:13.0:provided
    [INFO]    +- io.javaslang:javaslang:jar:2.0.6:provided
    [INFO]    |  \- io.javaslang:javaslang-match:jar:2.0.6:provided
    [INFO]    \- org.glassfish.jersey.core:jersey-common:jar:2.35:provided (version managed from 2.23.2)
    [INFO]       +- jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:provided (version managed from 2.1.6)
    [INFO]       +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:provided (version managed from 1.3.5)
    [INFO]       +- org.osgi:org.osgi.core:jar:6.0.0:provided
    [INFO]       +- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:provided
    [INFO]       \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:provided
    [INFO]          +- org.osgi:osgi.core:jar:6.0.0:provided
    [INFO]          \- org.osgi:osgi.cmpn:jar:6.0.0:provided
    [INFO]
    [INFO] ------------------------< com.example:module2 >-------------------------
    [INFO] Building module2 0.0.1-SNAPSHOT                                    [3/4]
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-dependency-plugin:3.3.0:tree (default-cli) @ module2 ---
    [INFO] com.example:module2:jar:0.0.1-SNAPSHOT
    [INFO] +- com.example:module1:jar:0.0.1-SNAPSHOT:compile
    [INFO] |  \- (com.alibaba:fastjson:jar:1.2.46:compile - omitted for conflict with 1.2.56)
    [INFO] \- com.alibaba:fastjson:jar:1.2.56:compile
    [INFO]    +- com.squareup.retrofit2:retrofit:jar:2.1.0:provided
    [INFO]    |  \- (com.squareup.okhttp3:okhttp:jar:4.9.3:provided - version managed from 3.3.0; omitted for duplicate)
    [INFO]    +- com.squareup.okhttp3:okhttp:jar:4.9.3:provided (version managed from 3.6.0)
    [INFO]    |  +- com.squareup.okio:okio:jar:2.8.0:provided
    [INFO]    |  |  +- (org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided - version managed from 1.4.0; omitted for duplicate)
    [INFO]    |  |  \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided (version managed from 1.4.0)
    [INFO]    |  \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided (version managed from 1.4.10)
    [INFO]    |     +- (org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided - version managed from 1.6.21; omitted for duplicate)
    [INFO]    |     \- org.jetbrains:annotations:jar:13.0:provided
    [INFO]    +- io.javaslang:javaslang:jar:2.0.6:provided
    [INFO]    |  \- io.javaslang:javaslang-match:jar:2.0.6:provided
    [INFO]    +- org.glassfish.jersey.core:jersey-common:jar:2.35:provided (version managed from 2.23.2)
    [INFO]    |  +- jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:provided (version managed from 2.1.6)
    [INFO]    |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:provided (version managed from 1.3.5)
    [INFO]    |  +- org.osgi:org.osgi.core:jar:6.0.0:provided
    [INFO]    |  +- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:provided
    [INFO]    |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:provided
    [INFO]    |     +- org.osgi:osgi.core:jar:6.0.0:provided
    [INFO]    |     \- org.osgi:osgi.cmpn:jar:6.0.0:provided
    [INFO]    \- joda-time:joda-time:jar:2.10:provided
    [INFO]
    [INFO] -------------------------< com.example:start >--------------------------
    [INFO] Building start 0.0.1-SNAPSHOT                                      [4/4]
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-dependency-plugin:3.3.0:tree (default-cli) @ start ---
    [INFO] com.example:start:jar:0.0.1-SNAPSHOT
    [INFO] +- com.example:module1:jar:0.0.1-SNAPSHOT:compile
    [INFO] |  \- com.alibaba:fastjson:jar:1.2.46:compile
    [INFO] |     +- com.squareup.retrofit2:retrofit:jar:2.1.0:provided
    [INFO] |     |  \- (com.squareup.okhttp3:okhttp:jar:4.9.3:provided - version managed from 3.3.0; omitted for duplicate)
    [INFO] |     +- com.squareup.okhttp3:okhttp:jar:4.9.3:provided (version managed from 3.6.0)
    [INFO] |     |  +- com.squareup.okio:okio:jar:2.8.0:provided
    [INFO] |     |  |  +- (org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided - version managed from 1.4.0; omitted for duplicate)
    [INFO] |     |  |  \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided (version managed from 1.4.0)
    [INFO] |     |  \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.6.21:provided (version managed from 1.4.10)
    [INFO] |     |     +- (org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.6.21:provided - version managed from 1.6.21; omitted for duplicate)
    [INFO] |     |     \- org.jetbrains:annotations:jar:13.0:provided
    [INFO] |     +- io.javaslang:javaslang:jar:2.0.6:provided
    [INFO] |     |  \- io.javaslang:javaslang-match:jar:2.0.6:provided
    [INFO] |     \- org.glassfish.jersey.core:jersey-common:jar:2.35:provided (version managed from 2.23.2)
    [INFO] |        +- jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:provided (version managed from 2.1.6)
    [INFO] |        +- (jakarta.annotation:jakarta.annotation-api:jar:1.3.5:provided - version managed from 1.3.5; omitted for duplicate)
    [INFO] |        +- org.osgi:org.osgi.core:jar:6.0.0:runtime (scope not updated to runtime)
    [INFO] |        +- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:provided
    [INFO] |        \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:provided
    [INFO] |           +- org.osgi:osgi.core:jar:6.0.0:provided
    [INFO] |           \- org.osgi:osgi.cmpn:jar:6.0.0:provided
    [INFO] +- com.example:module2:jar:0.0.1-SNAPSHOT:compile
    [INFO] |  +- (com.example:module1:jar:0.0.1-SNAPSHOT:compile - version managed from 0.0.1-SNAPSHOT; omitted for duplicate)
    [INFO] |  \- (com.alibaba:fastjson:jar:1.2.56:compile - omitted for conflict with 1.2.46)
    [INFO] +- org.springframework.boot:spring-boot-starter:jar:2.7.1:compile
    [INFO] |  +- org.springframework.boot:spring-boot:jar:2.7.1:compile (version managed from 2.7.1; scope not updated to compile)
    [INFO] |  |  +- (org.springframework:spring-core:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  |  \- org.springframework:spring-context:jar:5.3.21:compile (version managed from 5.3.21)
    [INFO] |  |     +- org.springframework:spring-aop:jar:5.3.21:compile (version managed from 5.3.21)
    [INFO] |  |     |  +- (org.springframework:spring-beans:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  |     |  \- (org.springframework:spring-core:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  |     +- org.springframework:spring-beans:jar:5.3.21:compile (version managed from 5.3.21)
    [INFO] |  |     |  \- (org.springframework:spring-core:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  |     +- (org.springframework:spring-core:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  |     \- org.springframework:spring-expression:jar:5.3.21:compile (version managed from 5.3.21)
    [INFO] |  |        \- (org.springframework:spring-core:jar:5.3.21:compile - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.7.1:compile (version managed from 2.7.1; scope not updated to compile)
    [INFO] |  |  \- (org.springframework.boot:spring-boot:jar:2.7.1:compile - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.7.1:compile (version managed from 2.7.1)
    [INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.11:compile (version managed from 1.2.11)
    [INFO] |  |  |  +- ch.qos.logback:logback-core:jar:1.2.11:compile (version managed from 1.2.11)
    [INFO] |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.36:compile - version managed from 1.7.32; omitted for duplicate)
    [INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile (version managed from 2.17.2)
    [INFO] |  |  |  +- (org.slf4j:slf4j-api:jar:1.7.36:compile - version managed from 1.7.35; omitted for duplicate)
    [INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile (version managed from 2.17.2)
    [INFO] |  |  |     \- (org.osgi:org.osgi.core:jar:4.3.1:provided - omitted for conflict with 6.0.0)
    [INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile (version managed from 1.7.36)
    [INFO] |  |     \- (org.slf4j:slf4j-api:jar:1.7.36:compile - version managed from 1.7.36; omitted for duplicate)
    [INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile (version managed from 1.3.5)
    [INFO] |  +- org.springframework:spring-core:jar:5.3.21:compile (version managed from 5.3.21; scope not updated to compile)
    [INFO] |  |  \- org.springframework:spring-jcl:jar:5.3.21:compile (version managed from 5.3.21)
    [INFO] |  \- org.yaml:snakeyaml:jar:1.30:compile (version managed from 1.30)
    [INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.7.1:runtime
    [INFO] |  +- (org.springframework.boot:spring-boot:jar:2.7.1:runtime - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  \- (org.springframework.boot:spring-boot-autoconfigure:jar:2.7.1:runtime - version managed from 2.7.1; omitted for duplicate)
    [INFO] +- org.projectlombok:lombok:jar:1.18.24:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.7.1:test
    [INFO] |  +- (org.springframework.boot:spring-boot-starter:jar:2.7.1:test - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.7.1:test (version managed from 2.7.1)
    [INFO] |  |  \- (org.springframework.boot:spring-boot:jar:2.7.1:test - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.7.1:test (version managed from 2.7.1)
    [INFO] |  |  +- (org.springframework.boot:spring-boot:jar:2.7.1:test - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  |  +- (org.springframework.boot:spring-boot-test:jar:2.7.1:test - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  |  \- (org.springframework.boot:spring-boot-autoconfigure:jar:2.7.1:test - version managed from 2.7.1; omitted for duplicate)
    [INFO] |  +- com.jayway.jsonpath:json-path:jar:2.7.0:test (version managed from 2.7.0)
    [INFO] |  |  +- net.minidev:json-smart:jar:2.4.8:test (version managed from 2.4.7)
    [INFO] |  |  |  \- net.minidev:accessors-smart:jar:2.4.8:test
    [INFO] |  |  |     \- org.ow2.asm:asm:jar:9.1:test
    [INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.36:compile (version managed from 1.7.33; scope not updated to compile)
    [INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:test (version managed from 2.3.3)
    [INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:1.2.2:test (version managed from 1.2.2)
    [INFO] |  +- org.assertj:assertj-core:jar:3.22.0:test (version managed from 3.22.0)
    [INFO] |  +- org.hamcrest:hamcrest:jar:2.2:runtime (version managed from 2.2; scope not updated to runtime)
    [INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.8.2:test (version managed from 5.8.2)
    [INFO] |  |  +- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test (version managed from 5.8.2)
    [INFO] |  |  |  +- org.opentest4j:opentest4j:jar:1.2.0:test
    [INFO] |  |  |  +- org.junit.platform:junit-platform-commons:jar:1.8.2:test (version managed from 1.8.2)
    [INFO] |  |  |  |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
    [INFO] |  |  |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
    [INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.8.2:test (version managed from 5.8.2)
    [INFO] |  |  |  +- (org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test - version managed from 5.8.2; omitted for duplicate)
    [INFO] |  |  |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
    [INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.8.2:test (version managed from 5.8.2)
    [INFO] |  |     +- org.junit.platform:junit-platform-engine:jar:1.8.2:test (version managed from 1.8.2)
    [INFO] |  |     |  +- (org.opentest4j:opentest4j:jar:1.2.0:test - omitted for duplicate)
    [INFO] |  |     |  +- (org.junit.platform:junit-platform-commons:jar:1.8.2:test - version managed from 1.8.2; omitted for duplicate)
    [INFO] |  |     |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
    [INFO] |  |     +- (org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test - version managed from 5.8.2; omitted for duplicate)
    [INFO] |  |     \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
    [INFO] |  +- org.mockito:mockito-core:jar:4.5.1:test (version managed from 4.5.1)
    [INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.12.11:test (version managed from 1.12.9)
    [INFO] |  |  |  +- net.java.dev.jna:jna:jar:5.8.0:runtime
    [INFO] |  |  |  +- (net.java.dev.jna:jna-platform:jar:5.8.0:test - omitted for conflict with 5.7.0)
    [INFO] |  |  |  +- com.google.code.findbugs:findbugs-annotations:jar:3.0.1:test
    [INFO] |  |  |  \- com.google.code.findbugs:jsr305:jar:3.0.2:runtime (scope not updated to runtime)
    [INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.12.11:test (version managed from 1.12.9)
    [INFO] |  |  |  +- (net.java.dev.jna:jna:jar:5.8.0:test - omitted for duplicate)
    [INFO] |  |  |  +- (net.java.dev.jna:jna-platform:jar:5.8.0:test - omitted for conflict with 5.7.0)
    [INFO] |  |  |  +- (com.google.code.findbugs:findbugs-annotations:jar:3.0.1:test - omitted for duplicate)
    [INFO] |  |  |  \- (com.google.code.findbugs:jsr305:jar:3.0.2:test - omitted for duplicate)
    [INFO] |  |  \- org.objenesis:objenesis:jar:3.2:test
    [INFO] |  +- org.mockito:mockito-junit-jupiter:jar:4.5.1:test (version managed from 4.5.1)
    [INFO] |  |  +- (org.mockito:mockito-core:jar:4.5.1:test - version managed from 4.5.1; omitted for duplicate)
    [INFO] |  |  \- (org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test - version managed from 5.8.2; omitted for duplicate)
    [INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test (version managed from 1.5.0)
    [INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
    [INFO] |  +- (org.springframework:spring-core:jar:5.3.21:test - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  +- org.springframework:spring-test:jar:5.3.21:test (version managed from 5.3.21)
    [INFO] |  |  \- (org.springframework:spring-core:jar:5.3.21:test - version managed from 5.3.21; omitted for duplicate)
    [INFO] |  \- org.xmlunit:xmlunit-core:jar:2.9.0:test (version managed from 2.9.0)
    [INFO] \- org.springframework.boot:spring-boot-maven-plugin:jar:2.7.1:compile
    [INFO]    +- org.springframework.boot:spring-boot-buildpack-platform:jar:2.7.1:runtime (version managed from 2.7.1)
    [INFO]    |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.3:runtime (version managed from 2.13.3)
    [INFO]    |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.3:runtime (version managed from 2.13.3)
    [INFO]    |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.13.3:runtime (version managed from 2.13.3)
    [INFO]    |  +- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.13.3:runtime (version managed from 2.13.3)
    [INFO]    |  |  +- (com.fasterxml.jackson.core:jackson-core:jar:2.13.3:runtime - version managed from 2.13.3; omitted for duplicate)
    [INFO]    |  |  \- (com.fasterxml.jackson.core:jackson-databind:jar:2.13.3:runtime - version managed from 2.13.3; omitted for duplicate)
    [INFO]    |  +- net.java.dev.jna:jna-platform:jar:5.7.0:runtime (scope not updated to runtime)
    [INFO]    |  |  \- (net.java.dev.jna:jna:jar:5.7.0:runtime - omitted for conflict with 5.8.0)
    [INFO]    |  +- org.apache.commons:commons-compress:jar:1.21:runtime
    [INFO]    |  |  \- (org.osgi:org.osgi.core:jar:6.0.0:runtime - omitted for duplicate)
    [INFO]    |  +- org.apache.httpcomponents:httpclient:jar:4.5.13:runtime (version managed from 4.5.13)
    [INFO]    |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.15:runtime (version managed from 4.4.13)
    [INFO]    |  |  \- commons-codec:commons-codec:jar:1.15:runtime (version managed from 1.11)
    [INFO]    |  +- (org.springframework:spring-core:jar:5.3.21:runtime - version managed from 5.3.21; omitted for duplicate)
    [INFO]    |  \- org.tomlj:tomlj:jar:1.0.0:runtime
    [INFO]    |     +- org.antlr:antlr4-runtime:jar:4.7.2:runtime
    [INFO]    |     \- (com.google.code.findbugs:jsr305:jar:3.0.2:runtime - omitted for duplicate)
    [INFO]    +- org.springframework.boot:spring-boot-loader-tools:jar:2.7.1:runtime (version managed from 2.7.1)
    [INFO]    |  +- (org.apache.commons:commons-compress:jar:1.21:runtime - omitted for duplicate)
    [INFO]    |  \- (org.springframework:spring-core:jar:5.3.21:runtime - version managed from 5.3.21; omitted for duplicate)
    [INFO]    \- org.sonatype.plexus:plexus-build-api:jar:0.0.7:runtime
    [INFO]       +- org.codehaus.plexus:plexus-utils:jar:1.5.8:runtime
    [INFO]       |  \- org.codehaus.plexus:plexus-interpolation:jar:1.3:runtime
    [INFO]       \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:runtime
    [INFO]          +- junit:junit:jar:4.13.2:runtime (version managed from 3.8.1)
    [INFO]          |  \- org.hamcrest:hamcrest-core:jar:2.2:runtime (version managed from 1.3)
    [INFO]          |     \- (org.hamcrest:hamcrest:jar:2.2:runtime - version managed from 2.2; omitted for duplicate)
    [INFO]          +- (org.codehaus.plexus:plexus-utils:jar:1.0.4:runtime - omitted for conflict with 1.5.8)
    [INFO]          \- classworlds:classworlds:jar:1.1-alpha-2:runtime
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary for springbootmvndemo 0.0.1-SNAPSHOT:
    [INFO]
    [INFO] springbootmvndemo .................................. SUCCESS [  0.941 s]
    [INFO] module1 ............................................ SUCCESS [  0.106 s]
    [INFO] module2 ............................................ SUCCESS [  0.043 s]
    [INFO] start .............................................. SUCCESS [  0.272 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  1.876 s
    [INFO] Finished at: 2022-07-05T23:18:13+08:00
    [INFO] ------------------------------------------------------------------------
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234

    结论:
    经过分析springboog打包依旧遵循「二、单个Jar包内的依赖竞争」这一段落提到的3个原则:
    依赖传导原则 、最短路径优先原则、最先声明优先原则。

    不同子pom进行构建时会发现引入fastjson版本并不一致,而最终springboot项目打好的fat包中只有一个fastjson版本,那只是因为我们只关心了含main方法的启动类所在module生成的target文件(这个module通常命名是xxx-start,是可以直接运行的程序),也就是说最终生成的fat jar,我们只是使用了这个命名为xxx-start的module进行生成的而已。

    参考文章:
    https://blog.csdn.net/ttzommed/article/details/114984341

  • 相关阅读:
    【Golang】结构体详解
    方法的重载
    容器适配器【stack、queue、priority_queue和反向迭代器】
    网站搭建从零开始(0)--域名的选择与解析
    webpack之代码分离
    【C语言刷题】指针入门三题|字符串长度、字符串复制、两数交换
    Python逆向爬虫之scrapy框架,非常详细
    Linux安装docker详细步骤
    网络工程师知识点7
    docker启动已存在容器
  • 原文地址:https://blog.csdn.net/hl_java/article/details/125630381