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

将Spring Boot应用部署到Heroku时遇编译错误求助

解决Heroku部署Java/Spring应用的编译错误

核心问题

Heroku编译环境的JDK版本与你项目指定的编译目标版本(Java 11)不匹配,导致Maven编译失败。同时存在重复版本构建的警告,但这是次要问题,先解决版本不匹配的核心错误。


解决方案

1. 强制指定Heroku使用Java 11

在项目根目录创建或编辑system.properties文件,添加以下内容:

java.runtime.version=11

这个文件会告诉Heroku构建环境使用Java 11进行编译和运行。

2. 确保Maven编译配置一致(可选但建议)

检查项目pom.xml中的maven-compiler-plugin配置,保证source和target版本均为11,示例配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.10.1</version>
    <configuration>
        <source>11</source>
        <target>11</target>
    </configuration>
</plugin>

3. 处理重复版本构建警告

如果你的代码版本已被Heroku构建过,执行空提交触发新构建:

git commit --allow-empty -m "trigger fresh build"
git push heroku master

若你从非master分支部署,使用正确的分支推送命令:

git push heroku <你的分支名>:main

操作步骤总结

  1. 添加/修改system.properties指定Java 11
  2. 确认pom.xml的编译版本配置正确
  3. 提交变更(或空提交)后重新推送到Heroku

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 21:09:21