我在我的项目中使用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
就不会出现这样的警告了。 但是后续运行又会再次出现警告。
*.*
,而murder-1.0-SNAPSHOT.jar
与*.*
匹配。 - undefinedfilter
来排除我的自己的文件,但是这样完全将所有我的文件从jar包中排除了。所以这个jar包只是充满了我的依赖项,而不是我的自己的类哈哈... - undefined