当前位置: 首页 > news >正文

maven Problem shading JAR的几个解决方案

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 解决方法

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>

相关文章:

  • java进阶学习脑图
  • deepseek_v3_base和deepseek_r1_zero和deepseek_r1
  • 【深入浅出:Core-JS Legacy 的降级兼容指南】
  • Filter-入门
  • uni-app 登录成功后自动跳转至登录前页面(H5\微信小程序)
  • 实战篇-java8中的垃圾回收器
  • python绑定udp时使用127.0.0.1作为ip,无法sendto,报错Invalid argument
  • Android 键盘输入按确认或换行 直接触发提交
  • 了解 PoE 扩展模式(Extend Mode)及其对数据速率的影响
  • python爬虫系列课程4:一个例子学会使用xpath语法
  • RK3399 Android7双WiFi功能实现
  • Python驱动的餐饮企业智能数据分析:从数据清洗到可视化决策全流程实战
  • 单片机的串口(USART)
  • JSPSSM526SpringBoot 教师人事档案管理系统功能说明
  • ROS的action通信——实现阶乘运算(二)
  • Android MMKV集成指南
  • MOE结构解读和deepseek的MoE结构
  • 【嵌入式Linux应用开发基础】网络编程(3):TCP协议拥塞控制
  • 获取GitHub的OAuth2的ClientId和ClientSecrets
  • 蓝桥杯嵌入式客观题以及解释
  • 微信网站在线登录网页版/百度小说排行榜风云榜单
  • 无极网站维护/首页优化公司
  • 如何做测评视频网站/百度seo公司哪家强一点
  • 展示系统 网站模板免费下载/聊城seo培训
  • 珠海哪里做网站的/企业网站的作用有哪些
  • 利用access数据库做网站/微信推广费用一般多少