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

Spring Boot Maven Plugin build-image报错:creator生命周期执行失败

解决Spring Boot build-image构建时TOML文件NULL字节错误(Intel Mac)

环境信息

  • 系统环境:Mac OS 13.5.2(22G91),1.4 GHz 四核Intel Core i5
  • 开发环境:
    • JVM:java 17.0.2 2022-01-18 LTS
    • Spring Boot:2.4.3
    • Maven:Apache Maven 3.6.3(cecedd343002696d0abb50b32b541b8a6ba2883f)
  • Docker环境:
    Client:
    Cloud integration: v1.0.35-desktop+001
    Version:           24.0.5
    API version:       1.43
    Go version:        go1.20.6
    Git commit:        ced0996
    Built:             Fri Jul 21 20:32:30 2023
    OS/Arch:           darwin/amd64
    Context:           desktop-linux
    Server: Docker Desktop 4.22.1(118664)
    Engine:
    Version:          24.0.5
    API version:      1.43(最低版本1.12)
    Go version:       go1.20.6
    Git commit:       a61e2b4
    Built:            Fri Jul 21 20:35:45 2023
    OS/Arch:          linux/amd64
    Experimental:     false
    containerd:
    Version:          1.6.21
    GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
    runc:
    Version:          1.1.7
    GitCommit:        v1.1.7-0-g860f061
    docker-init:
    Version:          0.19.0
    GitCommit:        de40ad0
    

错误现象

执行命令 mvn -e spring-boot:build-image 时构建失败,核心错误提示:

[creator] 错误:初始化检测器失败:toml: 第1行:文件不能包含NULL字节;可能使用了UTF-16;TOML文件必须为UTF-8

完整错误日志:

[INFO]  > 运行creator
[INFO]     [creator]     警告:请求的平台使用已弃用的API '0.4'
[INFO]     [creator]     ===> 检测中
[INFO]     [creator]     错误:初始化检测器失败:toml: 第1行:文件不能包含NULL字节;可能使用了UTF-16;TOML文件必须为UTF-8
[INFO] ------------------------------------------------------------------------
[INFO] 构建失败
[INFO] ------------------------------------------------------------------------
[INFO] 总耗时:  27.387 s
[INFO] 完成时间: 2023-09-09T09:43:41+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] 无法执行目标org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image(default-cli):执行default-cli目标失败,Builder lifecycle 'creator'返回状态码1 -> [帮助1]
org.apache.maven.lifecycle.LifecycleExecutionException: 无法执行目标org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image(default-cli):执行default-cli目标失败,Builder lifecycle 'creator'返回状态码1

Caused by: org.apache.maven.plugin.PluginExecutionException: 执行default-cli目标org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image失败:Builder lifecycle 'creator'返回状态码1

注意:同一项目在M1芯片Mac上执行相同命令可正常构建,已尝试版本调整、系统升级,问题仍存在。

解决方案

1. 检查项目TOML文件编码

排查项目内所有.toml文件(如buildpacks.toml或自定义配置文件):

  • 用文本编辑器(如VS Code)打开文件,查看右下角编码标识
  • 若为UTF-16,直接转换为UTF-8后保存,确保文件无NULL字节

2. 清理Buildpacks本地缓存

Buildpacks可能缓存了损坏的配置文件,执行以下命令清理:

rm -rf ~/.cache/paketo-buildpacks

清理完成后重新执行构建命令。

3. 匹配Spring Boot与插件版本

当前插件版本2.6.4与Spring Boot 2.4.3存在版本不匹配,修改pom.xml中插件版本为2.4.3:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.4.3</version> <!-- 与Spring Boot版本保持一致 -->
</plugin>

4. 指定兼容的Buildpacks Builder镜像

弃用的API版本0.4可能引发兼容性问题,在插件配置中指定Intel架构兼容的最新Builder:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.4.3</version>
    <configuration>
        <image>
            <builder>paketobuildpacks/builder-jammy-base:latest</builder>
        </image>
    </configuration>
</plugin>

5. 调整Docker平台参数

切换Docker Context并指定架构平台:

# 切换到默认Docker Context
docker context use default
# 指定amd64平台构建
mvn -e spring-boot:build-image -Dspring-boot.build-image.platform=linux/amd64

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 04:05:05