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

多模块Maven项目中Google Jib插件构建失败问题排查

多模块Spring Boot项目使用Jib构建镜像失败问题

项目结构

parent
+ lib_one
+ lib_two
+ spring-parent
  + spring-config
  + spring-app

当前配置情况

  1. 父pom中添加Jib插件全局配置:
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.4.0</version>
    <configuration>
      <from>
        <image>eclipse-temurin:21-jre-ubi9-minimal</image>
      </from>
      <to>
        <image>DOCKERIMAGE</image>
        <tags>
          <tag>${project.version}</tag>
          <tag>latest</tag>
        </tags>
     </to>
     <container>
      <ports>
        <port>8080</port>
      </ports>
    </container>
  </configuration>
</plugin>
  1. 无需构建容器的子模块(lib_one、lib_two、spring-config)添加Spring Boot插件跳过配置:
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <skip>true</skip>
  </configuration>
</plugin>
  1. spring-app模块配置<skip>false</skip>,保留Spring Boot插件正常执行。

执行命令及错误信息

在根目录执行命令:

mvn clean compile jib:build

触发异常:

Obtaining project build output files failed; make sure you have compiled your project before trying to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean compile jib:build"?)

使用环境:Java 21、Spring Boot 3.1


问题原因及解决方案

你只跳过了非应用模块的Spring Boot插件,但Jib插件默认会在所有模块执行。那些类库/配置模块没有可打包的Spring Boot应用代码,执行jib:build时无法找到符合要求的编译输出,因此报错。

解决步骤:

  1. 父pom中默认跳过Jib插件,让所有子模块默认不执行Jib构建:
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.4.0</version>
    <configuration>
      <!-- 原有from/to/container配置保持不变 -->
      <from>
        <image>eclipse-temurin:21-jre-ubi9-minimal</image>
      </from>
      <to>
        <image>DOCKERIMAGE</image>
        <tags>
          <tag>${project.version}</tag>
          <tag>latest</tag>
        </tags>
     </to>
     <container>
      <ports>
        <port>8080</port>
      </ports>
    </container>
    <!-- 添加默认跳过配置 -->
    <skip>true</skip>
  </configuration>
</plugin>
  1. 在spring-app模块中覆盖Jib跳过配置,启用该模块的镜像构建:
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <configuration>
        <skip>false</skip>
        <!-- 如需单独调整该模块的Jib参数,可在此添加 -->
    </configuration>
</plugin>
  1. 优化执行命令(可选但推荐):
    在根目录执行时,指定只构建spring-app模块及其依赖,避免无用模块的Jib检查:
mvn clean compile jib:build -pl spring-parent/spring-app -am

-pl指定目标模块,-am自动构建该模块的所有依赖模块,确保编译完整。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 21:38:31