Maven Shade重复类警告

5

我在我的项目中使用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就不会出现这样的警告了。 但是后续运行又会再次出现警告。


你可以尝试排除你的jar文件... - undefined
我猜我会试一试,但是我不明白如何将我的jar文件(也就是我正在编译的jar文件)从自身中排除出去会有什么帮助... @dan1st - undefined
1
看起来问题是Maven在构建新的jar时试图包含你的旧jar。这可能是因为你包含了*.*,而murder-1.0-SNAPSHOT.jar*.*匹配。 - undefined
我试图使用一个filter来排除我的自己的文件,但是这样完全将所有我的文件从jar包中排除了。所以这个jar包只是充满了我的依赖项,而不是我的自己的类哈哈... - undefined
只需排除您自己生成的jar文件即可。 - undefined
1个回答

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>

传奇。它有效。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接