Maven 将特定版本排除在 fat jar 中

Maven exclusions specific version into fat jar

我在项目中工作,其中 Springboot jar 和 Hive jar 由于版本重复而产生冲突

   <dependency>
        <groupId>org.apache.hive</groupId>
        <artifactId>hive-jdbc</artifactId>
        <version>3.1.0.3.1.0.0-78</version>
 </dependency>

上面的 hive jar 是 fat jar 并且有很多重复的依赖,在下面的例子中你可以看到两个版本 2.6.0 和 3.1.1.3.1.0.0-78

现在如果我们想添加排除

        <exclusions>
            <exclusion>
                <artifactId>XX</artifactId>
                <groupId>YYY</groupId>
            </exclusion>
         </exclusions>

Now i want to exclude only 2.6.0 version and keep 3 3.1.1.3.1.0.0-78 , is there any option where we can defined excluded jar version ?

[WARNING] 
Dependency convergence error for org.apache.hadoop:hadoop-auth:2.6.0 paths to dependency are:
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
  +-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
    +-org.apache.hive:hive-common:3.1.0.3.1.0.0-78
      +-com.github.joshelser:dropwizard-metrics-hadoop-metrics2-reporter:0.1.2
        +-org.apache.hadoop:hadoop-common:2.6.0
          +-org.apache.hadoop:hadoop-auth:2.6.0
and
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
  +-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
    +-org.apache.hive:hive-service:3.1.0.3.1.0.0-78
      +-org.apache.hive:hive-llap-server:3.1.0.3.1.0.0-78
        +-org.apache.hbase:hbase-hadoop2-compat:2.0.2.3.1.0.0-78
          +-org.apache.hadoop:hadoop-mapreduce-client-core:3.1.1.3.1.0.0-78
            +-org.apache.hadoop:hadoop-yarn-common:3.1.1.3.1.0.0-78
              +-org.apache.hadoop:hadoop-auth:3.1.1.3.1.0.0-78
and
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
  +-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
    +-org.apache.hive:hive-service:3.1.0.3.1.0.0-78
      +-org.apache.hive:hive-llap-server:3.1.0.3.1.0.0-78
        +-org.apache.hbase:hbase-server:2.0.2.3.1.0.0-78
          +-org.apache.hbase:hbase-http:2.0.2.3.1.0.0-78
            +-org.apache.hadoop:hadoop-auth:3.1.1.3.1.0.0-78

要解决依赖性收敛错误,请将条目添加到 <dependencyManagement>,您可以在其中指定所需的版本,例如

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>3.1.0.3.1.0.0-78</version>
</dependency>

然后所有通过传递找到的版本都将替换为您指定的版本,冲突消失。