You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Maven Shade Plugin覆盖依赖jar资源出现重复条目如何解决

问题原因

你使用IncludeResourceTransformer仅配置了加入自定义的资源文件,但第三方依赖中原有的同名资源仍会被打包进入最终的shaded jar,两者冲突触发重复条目报错。

解决方案

在shade插件配置中添加filters配置,先排除所有依赖(或指定目标第三方依赖)中的同名冲突资源,再保留你原有的自定义资源引入配置即可。

完整配置示例

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
        <execution>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <!-- 新增filters配置排除冲突资源 -->
                <filters>
                    <filter>
                        <!-- 若明确知道冲突资源所属的依赖,可替换为具体的groupId:artifactId,避免误排除 -->
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>assets/components/hystrixCommand/hystrixCommand.js</exclude>
                        </excludes>
                    </filter>
                </filters>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                        <resource>assets/components/hystrixCommand/hystrixCommand.js</resource>
                        <file>src/main/resources/hystrixCommand.js</file>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

补充说明

如果你的自定义资源文件已经放在项目的src/main/resources/assets/components/hystrixCommand/hystrixCommand.js路径下,和依赖中的资源路径完全一致,可以省略IncludeResourceTransformer配置,仅保留filters排除依赖中的同名资源即可,shade插件会自动将项目本地的资源打进最终jar包。

内容的提问来源于stack exchange,提问作者best wishes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 01:18:03