gpt4 book ai didi

java - Maven Shade 重叠类警告

转载 作者:行者123 更新时间:2023-12-05 08:05:47 28 4
gpt4 key购买 nike

我在我的项目中使用 commons-io 并想对其进行着色。我遇到了一个我似乎无法弄清楚的警告:

[WARNING] commons-io-2.7.jar, murder-1.0-SNAPSHOT.jar define 180 overlapping classes and resources:
...

我觉得这很奇怪,因为 murder-1.0-SNAPSHOT.jar是我要构建的 jar,它应该包括 commons-io jar。

我这样定义我的 commons-io 依赖:

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<scope>compile</scope>
</dependency>

(我以为我应该使用 runtime 范围,但后来我无法运行 package 因为它提示找不到 FileUtils)

这是我的 shade 插件配置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>

<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-io:commons-io</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

如果我删除 <filters>完全,我只收到这个警告:

commons-io-2.7.jar, murder-1.0-SNAPSHOT.jar define 1 overlapping resource
[WARNING] - META-INF/MANIFEST.MF

一切似乎仍然正常,但我想在打包时摆脱这个警告。

编辑:

如果我运行 mvn clean第一,下一个mvn package不产生这样的警告。然而,后续运行会再次引入警告。

最佳答案

最后,这就是我最终得到的结果,它似乎有效并且没有产生任何警告:

<properties>
<!-- replace this with wherever you want your shaded dependencies to end up -->
<shaded-dependencies>io.vapidlinus.shade</shaded-dependencies>
</properties>
....
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-io:commons-io</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.MF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.apache.commons.io</pattern>
<shadedPattern>${shaded-dependencies}.org.apache.commons.io</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>

关于java - Maven Shade 重叠类警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63659733/

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