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

使用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的规则:

    1. 查看<excludes>节点,确保没有org.postgresql:*这类排除项;
    2. 若配置了<includes>,确认PostgreSQL的包路径被包含在内;
    3. 确保插件绑定到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>
      
  • 清理缓存并重新构建

    1. 执行Maven命令强制清理并更新依赖:
      mvn clean install -U
      
    2. 在IntelliJ中,点击File -> Invalidate Caches...,勾选清除缓存并重启IDE,之后再执行Maven的package命令。
  • 对比两个项目的POM差异
    逐行对比正常项目与出问题项目的POM文件,包括父POM(若存在):

    • 检查PostgreSQL的依赖版本是否一致;
    • 查看是否有依赖管理(<dependencyManagement>)覆盖了scope;
    • 确认是否有激活的Maven Profile修改了插件或依赖配置。
  • 检查IntelliJ的Artifact配置

    1. 进入File -> Project Structure -> Artifacts,确认当前Artifact是基于Maven的target目录输出构建,而非手动添加的模块文件;
    2. 手动删除项目根目录下的target文件夹和IntelliJ生成的out文件夹,重新构建Artifact。

内容的提问来源于stack exchange,提问作者6footunder

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 12:31:03