迁移至Java 11 Runtime后Google App Engine部署失败求助
Ktor项目迁移Java 11至GAE部署失败解决方案
问题背景
原Java 8环境下正常部署的Ktor项目,迁移到Java 11 Runtime后部署报错。已完成以下配置变更:
- 替换
appengine-web.xml/web.xml为app.yaml - 配置
JAVA_HOME指向Java 11 - 更新
build.gradle的sourceCompatibility和targetCompatibility为11
关键配置
app.yaml
runtime: java11 entrypoint: 'ProjectName-1.0-SNAPSHOT.jar' instance_class: F1 automatic_scaling: max_pending_latency: 500ms min_idle_instances: 1 max_idle_instances: 1 max_concurrent_requests: 80 min_instances: 1 max_instances: 1 target_cpu_utilization: 0.95 target_throughput_utilization: 0.95
build.gradle
sourceCompatibility = 11 targetCompatibility = 11
报错日志
Starting Step #2 - "build" Step #2 - "build": Already have image (with digest): asia.gcr.io/gae-runtimes/buildpacks/google-gae-18/java/builder:java_20231016_RC00 Step #2 - "build": ===> ANALYZING Step #2 - "build": ERROR: failed to initialize analyzer: getting previous image: getting config file for image "asia.gcr.io/projectName/app-engine-tmp/app/default/ttl-18h:latest": GET https://storage.googleapis.com/asia.artifacts.prjectname.appspot.com/containers/images/sha256:{theHashCodeHere}?access_token=REDACTED: unexpected status code 404 Not Found: <?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Details>No such object: asia.artifacts.projectname.appspot.com/containers/images/sha256:{theHashCodeHere}</Details></Error> Finished Step #2 - "build" ERROR ERROR: build step 2 "asia.gcr.io/gae-runtimes/buildpacks/google-gae-18/java/builder:java_20231016_RC00" failed: step exited with non-zero status: 1
解决方法
1. 强制跳过构建缓存
报错核心是buildpack尝试复用已不存在的旧构建镜像,执行部署命令时添加--no-cache参数强制从头构建:
gcloud app deploy --no-cache
2. 修正entrypoint启动命令
Java 11 Runtime要求明确指定Java启动命令,不能直接写Jar文件名,修改app.yaml的entrypoint:
entrypoint: 'java -jar ProjectName-1.0-SNAPSHOT.jar'
若Jar文件在子目录(如build/libs),需补充完整相对路径:
entrypoint: 'java -jar build/libs/ProjectName-1.0-SNAPSHOT.jar'
3. 检查Artifact Registry权限
确保部署账号拥有roles/artifactregistry.writer或更高权限,同时确认项目的Artifact Registry仓库(asia.artifacts.projectname.appspot.com)已存在(GAE通常自动创建,若缺失可手动创建)。
4. 更新gcloud CLI到最新版本
旧版本CLI可能与Java 11 Runtime的buildpack存在兼容性问题,执行更新:
gcloud components update
内容的提问来源于stack exchange,提问作者Anudeep Ananth
相关产品推荐
相关产品推荐

