替换构建maven胖罐的传递依赖

问题描述 投票:0回答:1

我正在尝试用最新的依赖替换传递依赖,同时创建我的胖罐。但每次旧的依赖包含在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>

任何帮助将不胜感激。

java maven maven-assembly-plugin maven-shade-plugin
1个回答
1
投票

尝试重新排序依赖项。

通过传递依赖性将依赖关系保留在依赖关系之上的依赖关系中。

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-matter
2. https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies
© www.soinside.com 2019 - 2024. All rights reserved.