Maven Shade 重叠类警告

Vap*_*nus 5 java maven maven-shade-plugin apache-commons-io

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

[WARNING] commons-io-2.7.jar, murder-1.0-SNAPSHOT.jar define 180 overlapping classes and resources:
...
Run Code Online (Sandbox Code Playgroud)

我觉得这很奇怪,因为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>
Run Code Online (Sandbox Code Playgroud)

(我以为我应该使用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>
Run Code Online (Sandbox Code Playgroud)

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

commons-io-2.7.jar, murder-1.0-SNAPSHOT.jar define 1 overlapping resource
[WARNING]   - META-INF/MANIFEST.MF
Run Code Online (Sandbox Code Playgroud)

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

编辑:

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

Vap*_*nus 0

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

<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>
Run Code Online (Sandbox Code Playgroud)