【问题标题】:Maven Shade overlapping classes warningMaven Shade 重叠类警告
【发布时间】:2020-08-30 16:38:40
【问题描述】:

我在我的项目中使用 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

这是我的阴影插件配置:

<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>

如果我完全删除 &lt;filters&gt;,我只会收到以下警告:

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

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

编辑:

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

【问题讨论】:

  • 您可以尝试排除您的 jar...
  • 我想我会试一试,但我不明白如何排除我自己的 jar(这是我正在编译的 jar)本身会有所帮助...@dan1st
  • 似乎问题在于 maven 在构建新 jar 时试图包含您的旧 jar。这可能是因为您包含 *.*murder-1.0-SNAPSHOT.jar 匹配 *.*
  • 我尝试使用filter 排除我自己的文件,但这完全从 jar 中排除了我的所有文件。所以这个 jar 只是充满了我的依赖项,但没有我自己的类哈哈......
  • 排除您自己的自动生成的 jar 就足够了。

标签: java maven maven-shade-plugin apache-commons-io


【解决方案1】:

最后,这就是我最终的结果,它似乎可以工作并且不会产生任何警告:

<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>

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 2013-11-28
    • 2012-02-11
    • 2017-10-28
    • 2021-01-14
    • 2014-11-04
    • 2014-09-05
    • 2012-04-05
    相关资源
    最近更新 更多