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

如何在Spring Boot Maven构建镜像时指定使用Amazon Corretto 17?

强制使用Java 17 Amazon Corretto构建Docker镜像

核心解决步骤

1. 修正环境变量配置层级

你的现有配置中环境变量放在image子节点下,可能存在传递失效的问题,建议将env配置提升到插件的根configuration层级,确保变量被Paketo构建流程正确接收:

<build>
    <finalName>xyz</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-image</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.abc.MyApp</mainClass>
                        <builder>paketobuildpacks/builder:full</builder>
                        <env>
                            <BP_JVM_VERSION>17</BP_JVM_VERSION>
                            <BP_JAVA_RUNTIME>corretto</BP_JAVA_RUNTIME>
                        </env>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2. 清理构建缓存

之前的构建缓存可能保留了BellSoft Liberica的环境,导致新配置无法生效。执行构建时添加清理缓存参数:

mvn spring-boot:build-image -Dspring-boot.build-image.clean-cache=true

3. 直接指定Amazon Corretto构建包

如果上述步骤无效,可以绕过构建器的默认选择逻辑,直接声明使用Amazon Corretto构建包:

<configuration>
    <mainClass>com.abc.MyApp</mainClass>
    <builder>paketobuildpacks/builder:full</builder>
    <buildpacks>
        <buildpack>paketobuildpacks/amazon-corretto:latest</buildpack>
        <buildpack>paketobuildpacks/spring-boot:latest</buildpack>
    </buildpacks>
    <env>
        <BP_JVM_VERSION>17</BP_JVM_VERSION>
    </env>
</configuration>

4. 验证构建日志

构建时重点检查日志,确认以下内容:

  • 出现Paketo Buildpack for Amazon Corretto相关条目
  • $BP_JVM_VERSION的值为17而非8.*

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 18:05:00