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

部署Spring Boot项目到Heroku遇invalid target release:11错误求助

Fixing "invalid target release: 11" When Deploying Spring Boot to Heroku

Hey there, sorry to hear you’ve spent 10 hours wrestling with this—let’s break down the fixes that should get your Spring Boot app deployed to Heroku smoothly. That "invalid target release: 11" error almost always means Heroku is trying to compile your code with a JDK version lower than 11, even though you’ve configured things locally. Here’s what to check:

1. Double-Check Your system.properties File

First, make sure your system.properties is in the root directory of your project (not inside src or any subfolder)—Heroku only looks for it there. The line should be exactly:

java.runtime.version=11

No extra spaces, typos, or capitalization issues here—even a tiny mistake can throw it off.

2. Verify Heroku’s Buildpack

Heroku uses buildpacks to determine how to build your app. If you’re not using the official Java buildpack, it might not respect your JDK version setting.

  • Run this command to check your current buildpack:
    heroku buildpacks
    
  • If it’s not heroku/java, set it to the official one:
    heroku buildpacks:set heroku/java
    

3. Refine Your Maven Compiler Configuration

Your pom.xml already sets source and target to 11, but adding the <release> tag ensures the compiler fully adheres to Java 11 standards. Update your maven-compiler-plugin to this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>11</source>
        <target>11</target>
        <release>11</release> <!-- Add this line -->
    </configuration>
</plugin>

This eliminates any ambiguity about which JDK version Maven should use for compilation.

4. Purge Heroku’s Build Cache

Old cached build artifacts can sometimes stick around and cause version mismatches. Clear the cache and redeploy:

heroku builds:cache:purge
git push heroku main

5. Confirm Heroku’s Runtime Java Version

After deploying (or even during a failed build), you can check what Java version Heroku is actually using:

heroku run java -version

This should output something like openjdk version "11.x.x"—if it doesn’t, go back and double-check the previous steps.

These steps should resolve the target release error. The core issue is almost always a mismatch between the JDK version you’re specifying and the one Heroku is using to build your app.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:57:00