[英]Maven resolved version doesn't match version in transitive dependency
我的項目 (A) 依賴於另一個專有項目 (B)。 B 將spring-jms
列為這樣的依賴項( spring.version
是[4.3.9.RELEASE, 4.3.18.RELEASE]
):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
A -> B -> spring-jms
但是,當我在 A 中運行mvn clean dependency:tree -Dverbose=true
時, spring-jms
以 5.1.14.RELEASE 的形式返回,這超出了 B 中指定的范圍。在樹中,spring-jms 被列出了兩次,並且兩個條目都有 5.1.14.RELEASE。
我沒有在 A 中列出 spring-jms。我知道我可以將它添加到 A 中的dependencyManagement
以解決問題,但我仍然想知道它為什么要解決該版本。
下面是顯示spring-jms
的樹的一部分。 這些是它列出的唯一地方。
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ project A ---
[INFO] project A
[INFO] +- project B
[INFO] | +- (org.springframework:spring-context:jar:5.1.14.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-jms:jar:5.1.14.RELEASE:compile
[INFO] | | \- (org.springframework:spring-messaging:jar:5.1.14.RELEASE:compile - version managed from 5.1.11.RELEASE; omitted for duplicate)
[INFO] | +- org.springframework:spring-aop:jar:5.1.14.RELEASE:compile
[INFO] | +- org.springframework:spring-oxm:jar:5.1.14.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:5.1.14.RELEASE:compile
[INFO] | +- (org.apache.commons:commons-collections4:jar:4.3:compile - omitted for duplicate)
[INFO] | +- org.bouncycastle:bcprov-jdk15on:jar:1.56:compile
[INFO] | +- org.springframework.integration:spring-integration-jms:jar:5.1.9.RELEASE:compile
[INFO] | | \- (org.springframework:spring-jms:jar:5.1.14.RELEASE:compile - version managed from 5.1.11.RELEASE; omitted for duplicate)
如果您的依賴項之一使用 5.1.14.RELEASE,則可能會發生這種情況。 如果您使用 IntelliJ,您可以使用右側的 maven 部分來檢查您的依賴項,您可以在那里找到。 然后您可以使用排除來刪除該依賴項
<dependency> <groupId>com.smaple.dependency</groupId> <artifactId>dependency</artifactId> <version>version</version> <exclusions> <exclusion> <groupId>springjms</groupId>... </exclusion> </exclusions> </dependency>
運行mvn dependency:tree
命令並嘗試找到 spring-jms 的所有外觀。
當 maven 解決依賴關系時,如果存在不同版本的依賴關系,它將在依賴關系樹的深度方面最接近根。
因此,如果您的項目具有以下樹:
YOUR_PROJECT
|___ <PROJECT_B>
| |__spring-jms-v1 // depth = 2
|___spring-jms-v2 // depth = 1
Maven 將采用spring-jms-v2
因為它更接近根
在任何情況下, mvn dependency:tree
都會顯示“根”的版本和完整路徑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.