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

推送Spring Boot应用到Heroku时pre-receive hook declined报错如何解决

问题解决方案

错误核心原因是Maven编译阶段目标JDK版本与Heroku构建环境的JDK版本不匹配。从日志可看到maven-compiler-plugin尝试编译到JDK 11目标版本,而你配置的Heroku运行时JDK为16,同时pom.xml中指定的java.version为11,三者版本不一致导致编译失败。

以下是两种可直接落地的解决路径:

方案一:统一使用Java 16

  • 修改pom.xml中properties节点的配置,将<java.version>11</java.version>调整为<java.version>16</java.version>,保证Maven编译的源码和目标版本与你使用的本地JDK版本一致。
  • 确认项目根目录的system.properties文件内容为java.runtime.version=16,且该文件已经通过git add+git commit提交到本地仓库,未被.gitignore忽略。

方案二:统一使用Java 11(兼容性更好,Spring Boot 2.5.4对Java 11的支持更稳定)

  • 直接删除项目根目录的system.properties文件,或修改文件内容为java.runtime.version=11,适配当前pom.xml中的JDK版本配置,Heroku默认的Java运行时版本就是11,无需额外配置也可正常识别。

可选优化配置

为避免Maven编译插件版本兼容问题,可在pom.xml的build/plugins节点下显式配置maven-compiler-plugin的版本和参数:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
</plugin>

最终推送操作

所有修改完成后,提交所有变更到git,重新执行推送命令即可:

git add .
git commit -m "fix: 统一JDK版本适配Heroku构建"
git push heroku master

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 15:39:01