Maven依赖导入错误的子依赖版本
Posted
技术标签:
【中文标题】Maven依赖导入错误的子依赖版本【英文标题】:Maven dependency imports wrong child dependencies versions 【发布时间】:2019-07-23 10:25:58 【问题描述】:我有一个依赖 https://mvnrepository.com/artifact/io.zipkin.reporter2/zipkin-sender-okhttp3/2.7.14 声明为
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-okhttp3</artifactId>
<version>2.7.14</version>
</dependency>
它的 pom 中的此依赖项与 pom 文件具有父依赖项,该文件声明如下依赖项:
<dependency>
<groupId>$project.groupId</groupId>
<artifactId>zipkin-reporter</artifactId>
<version>$project.version</version>
</dependency>
project.groupid 等于 io.zipkin.reporter2 和 project.version 等于 2.7.14。所以maven应该导入依赖<artifactId>zipkin-reporter</artifactId>
,版本等于2.7.14。 但是它会导入 2.2.0 版本。我没有在其他任何地方声明此依赖项,其他依赖项也没有将此依赖项视为可交互的。我尝试重新安装 maven,从 git 重新克隆项目,使缓存无效并重新启动 IDEA,删除 .m2 文件夹 - 没有任何效果。
奇怪的是,我有其他项目使用相同的依赖项(<artifactId>zipkin-sender-okhttp3</artifactId>
),并且所有版本都按应有的顺序排列。
有什么想法可以解决吗?
编辑:mvn 依赖:树输出(我编辑了敏感信息):`
mvn dependency:tree -Dverbose -Dincludes=io.zipkin.reporter2:zipkin-reporter
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.***.rnd.dep:***-deployment:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: commons-io:commons-io:jar -> duplicate declaration of version 2.6 @ com.***.rnd.dep:***-deployment:[unknown-version], C:\Users\nimi0218\Des
ktop\Projects\CJM(DEP)\***\***-deployment\pom.xml, line 70, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Notification Service [pom]
[INFO] ***-api [jar]
[INFO] ***-impl [jar]
[INFO] ***-sms [jar]
[INFO] ***-email [jar]
[INFO] ***-push [jar]
[INFO] ***-rest [jar]
[INFO] ***-mq [jar]
[INFO] ***-deployment [jar]
[INFO]
[INFO] ------------< com.***.rnd.dep:*** >-------------
[INFO] Building Notification Service 0.0.1-SNAPSHOT [1/9]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ *** ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***:pom:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ----------< com.***.rnd.dep:***-api >-----------
[INFO] Building ***-api 0.0.1-SNAPSHOT [2/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-api ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-api:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ----------< com.***.rnd.dep:***-impl >----------
[INFO] Building ***-impl 0.0.1-SNAPSHOT [3/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-impl ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-impl:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ----------< com.***.rnd.dep:***-sms >-----------
[INFO] Building ***-sms 0.0.1-SNAPSHOT [4/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-sms ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-sms:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ---------< com.***.rnd.dep:***-email >----------
[INFO] Building ***-email 0.0.1-SNAPSHOT [5/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-email ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-email:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ----------< com.***.rnd.dep:***-push >----------
[INFO] Building ***-push 0.0.1-SNAPSHOT [6/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-push ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-push:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] ----------< com.***.rnd.dep:***-rest >----------
[INFO] Building ***-rest 0.0.1-SNAPSHOT [7/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-rest ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-rest:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] -----------< com.***.rnd.dep:***-mq >-----------
[INFO] Building ***-mq 0.0.1-SNAPSHOT [8/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-mq ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-mq:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
[INFO]
[INFO] -------< com.***.rnd.dep:***-deployment >-------
[INFO] Building ***-deployment 0.0.1-SNAPSHOT [9/9]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ***-deployment ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.***.rnd.dep:***-deployment:jar:0.0.1-SNAPSHOT
[INFO] \- io.zipkin.reporter2:zipkin-sender-okhttp3:jar:2.7.14:compile
[INFO] \- io.zipkin.reporter2:zipkin-reporter:jar:2.2.0:compile (version managed from 2.7.14)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Notification Service 0.0.1-SNAPSHOT:
[INFO]
[INFO] Notification Service ............................... SUCCESS [ 22.484 s]
[INFO] ***-api ........................... SUCCESS [ 1.086 s]
[INFO] ***-impl .......................... SUCCESS [ 1.060 s]
[INFO] ***-sms ........................... SUCCESS [ 0.790 s]
[INFO] ***-email ......................... SUCCESS [ 0.960 s]
[INFO] ***-push .......................... SUCCESS [ 1.112 s]
[INFO] ***-rest .......................... SUCCESS [ 1.327 s]
[INFO] ***-mq ............................ SUCCESS [ 0.827 s]
[INFO] ***-deployment .................... SUCCESS [ 4.317 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.287 s
[INFO] Finished at: 2019-03-01T15:37:07+03:00
[INFO] ------------------------------------------------------------------------
` 所有模块的版本都应该是 2.7.7,但一个名为 ...-deployment 的模块的版本是 2.2.0。它没有在那里明确设置。
【问题讨论】:
我不确定,但可能有其他一些库正在使用此版本依赖项。我再说一遍,我不确定,但你可以弄清楚是否有。 看起来您正在使用 zipkin-reporter 的占位符。查看<project.version>
是否被<properties>
中的另一个 <project.version>
标签覆盖
请致电mvn dependency:tree
并将相关部分复制到问题中(通过编辑,而不是进入 cmets)。
@Clover 我查过了,没有
@JFMeier 已编辑
【参考方案1】:
你有
io.zipkin.reporter2:zipkin-reporter:jar:2.2.0:compile (version managed from 2.7.14)
这意味着在您的 POM 或您的父 POM 中有一个 <dependencyManagement>
条目将版本设置为 2.2.0
。
【讨论】:
我唯一拥有的<dependencyManagement>
是<groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId><version>Edgware.SR1</version>
,它不会影响 zipkin。我唯一能想到的是其他依赖项在其父或子 pom <dependencyManagement>
中具有降低 zipkin 的版本。
这有范围导入吗?
是的,确实如此。范围是import
。
然后你必须去那个pom并在那里查找所有的dependencyManagement(它是导入的)。如果您在其中有进一步的范围导入,则必须重复该过程。
我的其他组件中有相同的<dependencyManagement>
块,它工作得很好。我会这样做,但我几乎可以肯定情况并非如此。以上是关于Maven依赖导入错误的子依赖版本的主要内容,如果未能解决你的问题,请参考以下文章