gpt4 book ai didi

java - 替换构建 Maven fat jar 的传递依赖

转载 作者:行者123 更新时间:2023-12-02 10:09:01 25 4
gpt4 key购买 nike

我在创建我的 fat jar 时尝试用最新的传递依赖项替换传递依赖项。但每次旧的依赖项都会包含在 jar 中。我尝试过装配插件和阴影插件。这是我的 pom 的片段-

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_2.11</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>0.10.2.0</version>
</dependency>

Shade插件片段-

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.kafka:kafka-clients:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>

任何帮助将不胜感激。

最佳答案

尝试重新排序依赖关系。

将依赖关系与您想要的版本保持在通过传递依赖关系包含的依赖关系之上。

执行mvn dependency:tree几次才能正确。

示例:

<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>0.10.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_2.11</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
<!-- <exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
</exclusion>
</exclusions> -->
</dependency>

引用:

1. https://stackoverflow.com/questions/31740785/why-order-of-maven-dependencies-matter2. https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies

关于java - 替换构建 Maven fat jar 的传递依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55127485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com