簡體   English   中英

替換傳遞依賴項構建Maven胖子

[英]Replace a transitive dependency building maven 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>

陰影插件片段-

<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-matter
2. https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM