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

GitLab CI中Spring Boot Buildpacks启用BP_JVM_JLINK_ENABLED构建失败求助

问题

本地环境执行Spring Boot的bootBuildImage任务(开启BP_JVM_JLINK_ENABLED=true)构建正常,但在GitLab CI中执行时失败,核心错误如下:

[creator]       JLink: Contributing to layer
[creator]     unable to invoke layer creator
[creator]     unable to retrieve list of JVM modules for jlink
[creator]     unable to list modules
[creator]     exit status 1
[creator]     ERROR: failed to build: exit status 1

> Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootBuildImage'.
> Builder lifecycle 'creator' failed with status code 51

应用是通过Spring Initializr生成的简单项目,无特殊配置,Gradle相关配置如下:

tasks.named("bootBuildImage") {
    environment["BP_JVM_VERSION"] = "17"
    environment["BP_JVM_JLINK_ENABLED"] = "true"
} 

禁用BP_JVM_JLINK_ENABLED后CI流水线可正常构建,但希望通过该配置减小镜像体积,完整CI构建日志如下:

[32;1m$ ./gradlew build bootBuildImage --imageName=playground:abc�

Welcome to Gradle 7.5.1!

Here are the highlights of this release:

Support for Java 18
Support for building with Groovy 4
Much more responsive continuous builds
Improved diagnostics for dependency resolution
For more details see https://docs.gradle.org/7.5.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Task :compileJava
Task :processResources
Task :classes
Task :bootJarMainClassName
Task :bootJar
Task :jar SKIPPED
Task :assemble
Task :compileTestJava
Task :processTestResources NO-SOURCE
Task :testClasses
Task :test
Task :compileIntegrationTestJava NO-SOURCE
Task :processIntegrationTestResources NO-SOURCE
Task :integrationTestClasses UP-TO-DATE
Task :integrationTest NO-SOURCE
Task :spotlessInternalRegisterDependencies
Task :spotlessJava
Task :spotlessJavaCheck
Task :spotlessCheck

Task :jacocoTestReport
..
Task :check
Task :build

Task :bootBuildImage
Building image 'playground:abc'

Pulling builder image 'docker.io/paketobuildpacks/builder-jammy-base:latest' ..................................................
Pulled builder image 'paketobuildpacks/builder-jammy-base@sha256:ff47160c561329011180fcec8f3ae32c18c044ab9c57c3d981157309734693e9'
Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' ..................................................
Pulled run image 'paketo-buildpacks/run-jammy-base@sha256:436a84a3ae3bdbc9f0534b7e6a80122d05f734048137691fcfec36f8132758b1'
Executing lifecycle version v0.19.3
Using build cache volume 'pack-cache-4bc4e9944d46.build'

Running creator
[creator] ===> ANALYZING
[creator] Image with name "playground:abc" not found
[creator] ===> DETECTING
[creator] 6 of 26 buildpacks participating
[creator] paketo-buildpacks/ca-certificates 3.6.8
[creator] paketo-buildpacks/bellsoft-liberica 10.5.5
[creator] paketo-buildpacks/syft 1.45.0
[creator] paketo-buildpacks/executable-jar 6.8.5
[creator] paketo-buildpacks/dist-zip 5.6.10
[creator] paketo-buildpacks/spring-boot 5.27.11
[creator] ===> RESTORING
[creator] ===> BUILDING
[creator]
[creator] Paketo Buildpack for CA Certificates 3.6.8
[creator] https://github.com/paketo-buildpacks/ca-certificates
[creator] Launch Helper: Contributing to layer
[creator] Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
[creator]
[creator] Paketo Buildpack for BellSoft Liberica 10.5.5
[creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[creator] Build Configuration:
[creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[creator] $BP_JVM_JLINK_ENABLED true enables running jlink tool to generate custom JRE
[creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[creator] $BP_JVM_VERSION 17 the Java version
[creator] Launch Configuration:
[creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[creator] $BPL_JMX_PORT 5000 configure the JMX port
[creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[creator] Using Java version 17 from BP_JVM_VERSION
[creator] BellSoft Liberica JDK 17.0.10: Contributing to layer
[creator] Downloading from https://github.com/bell-sw/Liberica/releases/download/17.0.10+13/bellsoft-jdk17.0.10+13-linux-amd64.tar.gz
[creator] Verifying checksum
[creator] Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jdk
[creator] Adding 137 container CA certificates to JVM truststore
[creator] Writing env.build/JAVA_HOME.override
[creator] Writing env.build/JDK_HOME.override
[creator] JLink: Contributing to layer
[creator] unable to invoke layer creator
[creator] unable to retrieve list of JVM modules for jlink
[creator] unable to list modules
[creator] exit status 1
[creator] ERROR: failed to build: exit status 1

Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':bootBuildImage'.
Builder lifecycle 'creator' failed with status code 51
解决方案

针对GitLab CI中开启jlink构建失败的问题,可尝试以下几种解决思路:

  • 检查CI Runner资源限制:jlink生成自定义JRE需要一定内存和CPU资源,GitLab CI默认Runner配置可能资源不足。尝试增大Runner内存分配(建议2GB以上),避免资源耗尽导致jlink命令执行失败。

  • 显式指定JLink所需模块:默认Paketo Buildpack会自动检测依赖模块,但CI环境可能存在检测异常。通过设置BP_JVM_JLINK_ARGS显式添加必要模块,示例:

    tasks.named("bootBuildImage") {
        environment["BP_JVM_VERSION"] = "17"
        environment["BP_JVM_JLINK_ENABLED"] = "true"
        environment["BP_JVM_JLINK_ARGS"] = "--no-man-pages --no-header-files --strip-debug --compress=1 --add-modules java.base,java.logging,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument"
    }
    

    模块列表可根据Spring Boot应用实际依赖调整。

  • 升级Paketo Buildpack版本:当前使用的BellSoft Liberica Buildpack版本为10.5.5,可能存在CI环境兼容性问题。尝试切换到更新版本的builder镜像(如paketobuildpacks/builder-jammy-base:0.0.147或更新稳定版本),避免使用latest标签。

  • 跳过CA证书添加操作:日志显示构建中添加了137个容器CA证书到JVM信任库,这一步可能修改JDK文件导致jlink无法识别模块。可设置BP_CA_CERTIFICATES_ENABLED=false禁用该Buildpack验证:

    tasks.named("bootBuildImage") {
        environment["BP_JVM_VERSION"] = "17"
        environment["BP_JVM_JLINK_ENABLED"] = "true"
        environment["BP_CA_CERTIFICATES_ENABLED"] = "false"
    }
    

    若禁用后构建成功,再手动处理CA证书需求。

  • 使用预构建自定义JRE:若上述方法无效,可在本地环境通过jlink生成符合需求的自定义JRE,CI构建时直接使用该JRE,避免在CI环境执行jlink命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 00:09:52