Published on

maven 依赖中依赖的子包版本冲突

Authors
引入依赖1:
    <dependency>
          <groupId>net.devh</groupId>
          <artifactId>grpc-server-spring-boot-starter</artifactId>
          <version>2.10.1.RELEASE</version>
    </dependency>
引入依赖2:
    <dependency>
      <groupId>com.sanhe</groupId>
      <artifactId>fabricsdk</artifactId>
      <version>1.3.7</version>
    </dependency>

这两个依赖都引用了包 io.grpc:grpc-core,但是版本不一致,编译报错,冲突。

Failed to collect dependencies for
 com.sanhe:fabricservice:jar:1.0-SNAPSHOT:
  Could not resolve version conflict among
   [org.hyperledger.fabric-sdk-java:fabric-sdk-java:jar:1.4.7 -> io.grpc:grpc-netty:jar:1.23.0 -> io.grpc:grpc-core:jar:[1.23.0,1.23.0], net.devh:grpc-server-spring-boot-starter:jar:2.10.0.RELEASE -> net.devh:grpc-server-spring-boot-autoconfigure:jar:2.10.0.RELEASE -> net.devh:grpc-common-spring-boot:jar:2.10.0.RELEASE -> io.grpc:grpc-core:jar:1.31.1, net.devh:grpc-server-spring-boot-starter:jar:2.10.0.RELEASE -> net.devh:grpc-server-spring-boot-autoconfigure:jar:2.10.0.RELEASE -> io.grpc:grpc-netty-shaded:jar:1.31.1 -> io.grpc:grpc-core:jar:[1.31.1,1.31.1], net.devh:grpc-server-spring-boot-starter:jar:2.10.0.RELEASE -> net.devh:grpc-server-spring-boot-autoconfigure:jar:2.10.0.RELEASE -> io.grpc:grpc-services:jar:1.31.1 -> io.grpc:grpc-core:jar:[1.31.1,1.31.1]] -> [Help 1]

因为依赖2中的版本较低,屏蔽掉依赖2中的冲突包
<dependency>
      <groupId>com.sanhe</groupId>
      <artifactId>fabricsdk</artifactId>
      <version>1.3.7</version>
        <exclusions>
          <exclusion>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-core</artifactId>
          </exclusion>
        </exclusions>
    </dependency>

参考链接

https://www.cnblogs.com/xinruyi/p/11221371.html