我正在使用最近的 grpc-netty 依賴項。問題是它帶來了舊版本的 io.netty 依賴項(4.1.27) 我查看了 grpc-netty 專案,使用的 io.netty 依賴項版本是 4.1.63。知道讓這種依賴關系帶來舊版本的傳遞依賴關系的原因是什么嗎?
謝謝
uj5u.com熱心網友回復:
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http2</artifactId>
</exclusion>
</exclusions>
</dependency>
您需要排除標簽
uj5u.com熱心網友回復:
Maven 在選擇依賴版本時不會比較版本號。它只是選擇在執行廣度優先搜索時遇到的第一個版本。出于這個原因,gRPC 團隊強烈建議您使用 Maven強制執行requireUpperBoundDeps器來檢測您所面臨的問題:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireUpperBoundDeps/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
然后,要解決問題,有兩種方法:
- 重新排序依賴串列或重新定義傳遞依賴
- 使用 BOM
(1) 以Maven的廣度優先搜索為目標,擁有你想被Maven搜索首先“看到”的版本。例如,您可以在您的中重新排序netty-handler before ,那么 Maven 將首先遇到它并在 的直接依賴項之前選擇它的直接依賴項。當您無法重新排序以解決問題時,您可以在傳遞依賴項上添加顯式依賴項以顯式選擇其版本。例如,您可以在.grpc-netty<dependencies>grpc-nettynetty-resolver<dependencies>
(2) 適用于像 gRPC 和 Netty 這樣的多工件專案,您確實希望各種工件的版本一致。您通常不想將netty-buffer4.1.51.Final 與netty-codec-http24.1.27.Final 一起使用;你想要他們相同的版本。在這些情況下,您可以檢查專案是否具有 BOM。gRPC和 Netty 都有 BOM 。使用 BOM,您可以為該專案中的所有各種工件選擇一次使用的版本。BOM 是在節中定義的<dependencyManagement>,該節與<dependencies>.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>
<version>4.1.51.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
Whatever you do, don't exclude. Exclusions cause dependency trouble later because they hide the transitive dependencies. If a newer version of gRPC depends on a newer version of Netty, then you'd end up downgrading Netty. And at that point build tools can no longer detect or manage the problem; you'll only discover such issues at runtime.
It is clear from what you've shown that something more is going on in your pom.xml; you really need to share more of your pom to diagnose. But with the other answers telling you to exclude I wanted to show the more appropriate ways of resolving.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/425990.html
上一篇:java.lang.NoSuchMethodError:'com.google.common.collect.ImmutableMap嘗試使用Chromedriver和Maven執行測驗時出
