使用IntelliJ/Maven构建Uber Jar时缺失依赖组件问题
解决Flink应用Maven Shade打包后PostgreSQL依赖缺失问题
以下是针对该问题的具体排查和解决步骤:
检查PostgreSQL依赖的Scope
确认POM中postgresql依赖的scope为compile(默认值,但可能被修改),如果设置为provided或test,shade插件不会将其打包到Artifact中:<dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>你的版本号</version> <scope>compile</scope> </dependency>排查maven-shade-plugin配置
检查插件配置中是否存在排除PostgreSQL的规则:- 查看
<excludes>节点,确保没有org.postgresql:*这类排除项; - 若配置了
<includes>,确认PostgreSQL的包路径被包含在内; - 确保插件绑定到
package阶段,完整的基础配置示例:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <!-- 仅排除签名文件,不要涉及PostgreSQL --> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin>
- 查看
清理缓存并重新构建
- 执行Maven命令强制清理并更新依赖:
mvn clean install -U - 在IntelliJ中,点击
File -> Invalidate Caches...,勾选清除缓存并重启IDE,之后再执行Maven的package命令。
- 执行Maven命令强制清理并更新依赖:
对比两个项目的POM差异
逐行对比正常项目与出问题项目的POM文件,包括父POM(若存在):- 检查PostgreSQL的依赖版本是否一致;
- 查看是否有依赖管理(
<dependencyManagement>)覆盖了scope; - 确认是否有激活的Maven Profile修改了插件或依赖配置。
检查IntelliJ的Artifact配置
- 进入
File -> Project Structure -> Artifacts,确认当前Artifact是基于Maven的target目录输出构建,而非手动添加的模块文件; - 手动删除项目根目录下的
target文件夹和IntelliJ生成的out文件夹,重新构建Artifact。
- 进入
内容的提问来源于stack exchange,提问作者6footunder
相关产品推荐
相关产品推荐

