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

如何使用Spring Boot Maven插件仅执行镜像构建而不重新构建项目

Spring Boot build-image 跳过完整构建流程解决方案

spring-boot:build-image 目标默认绑定到 Maven 的 verify 生命周期阶段,直接执行该目标时,Maven 会按顺序执行 verify 之前的所有生命周期环节(包含资源处理、代码编译、测试执行、打包等),也就是你观察到的完整构建流程。
可以通过以下两种方式实现仅构建镜像、不执行完整构建流程的需求:

  • 方案1:临时跳过构建环节(适合单次使用场景)
    如果你已经完成过项目构建,target 目录下存在最新的可执行 Jar 包,可直接在构建命令中添加参数跳过所有构建环节:
    ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=myImage -Dmaven.resources.skip=true -Dmaven.main.skip=true -Dmaven.test.skip=true
    
    注意:执行前请确认 target 目录下的 Jar 包为最新构建产物,否则生成的镜像会包含旧版本代码
  • 方案2:修改插件绑定配置(适合长期使用场景)
    你可以在项目的 pom.xml 中调整 Spring Boot Maven 插件的配置,解除 build-image 目标和 verify 阶段的默认绑定:
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.5.x</version>
        <executions>
            <execution>
                <id>build-image</id>
                <phase>none</phase>
                <goals>
                    <goal>build-image</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
    配置完成后,后续执行 build-image 命令时就不会触发完整的 Maven 生命周期流程,只会执行镜像构建逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 13:36:07