1 现象
Error creating shaded jar: Problem shading JAR :xxxxxx.jar entry META-INF/versions/11/com/fasterxml/jackson/core/io/doubleparser/BigSignificand.class: java.lang.IllegalArgumentException -> [Help 1]
2 原因
这个问题通常是由于 maven-shade-plugin 在处理多版本 JAR 文件(Multi-Release JAR)时,无法正确处理 META-INF/versions 目录下的类文件。
META-INF/versions 是 Java 9 引入的多版本 JAR 文件特性,用于支持不同 Java 版本的类文件。
3 解决方法
mavenshadeplugin__11">3.1 方法1 升级 maven-shade-plugin 版本。
maven-shade-plugin 的较新版本已经对多版本 JAR 文件提供了更好的支持。尝试升级到最新版本(如 3.3.0 或更高版本)。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version> <!-- 使用较新版本 -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
3.2 方法2:排除冲突的依赖
如果升级插件版本无法解决问题,可以尝试排除 hadoop-huaweicloud 依赖中与 jackson-core 相关的冲突文件。
在 pom.xml 中添加排除规则:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>你的组:你的artifact</artifact>
<excludes>
<exclude>META-INF/versions/**</exclude>
<exclude>com/fasterxml/jackson/core/io/doubleparser/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
3.3 方法3:显式统一依赖的版本
如果问题是由于 jackson-core 的版本冲突引起的,可以尝试统一项目中所有依赖的 jackson-core 版本。
在 pom.xml 中显式指定 jackson-core 的版本:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version> <!-- 使用合适的版本 -->
</dependency>
3.4 方法4:禁用Shade插件的多版本支持
如果不需要多版本 JAR 文件的支持,可以通过配置maven-shade-plugin禁用对META-INF/versions 的处理。
在 pom.xml 中添加以下filter配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/versions/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>