[FIXED] Heroku Java Deploy Maven Error Invalid Target Release
- Details
- Written by Nam Ha Minh
- Last Updated on 19 October 2022   |   Print Email
remote: -----> Building on the Heroku-22 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Java app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Executing Maven
Whereas in the pom.xml file:<project ..> <properties> <java.version>11</java.version> </properties> </project>Understanding this, there are 2 solutions to fix this “invalid target release”:- Change Java version of your Maven project to the one installed by Heroku- Change JDK version installed by Heroku for new appsLet’s dive into each solution in details.
1. Fix “invalid target release” error by changing project’s Java version
Use this solution if you’re sure that your application still works normally with the default Java version used by Heroku (OpenJDK 1.8 by default). So just update Java version in the pom.xml file as follows:<project ..> <properties> <java.version>1.8</java.version> </properties> </project>Commit this change using the following commands: git add pom.xml
git commit -m “change Java version to 1.8”
Then use git push heroku master command to deploy the app again. The “invalid target release” error will be gone and the app will be deployed successfully.NOTES: to know which JDK version installed by Heroku, see the beginning lines of the deploy logs as shown above. And check this article to learn more about changing Java version for Maven project.2. Fix “invalid target release” error by changing JDK version on Heroku
Use this solution if your app must run with the Java version specified in the pom.xml file. So you need to tell Heroku to install a matching JDK version. Create a text file named system.properties under project root directory, with the following content:java.runtime.version=11
Then run the following Git commands to commit the change:git add system.properties
git commit -m “change Heroku java version to 11”
And run git push heroku master command to deploy the app again. You’ll get rid of the “invalid target release” error and get your app deployed.That’s my solution to fix Heroku Java deploy Maven error invalid target release. I hope you find it helpful. I recommend you watch the following video to see how to fix this error in action:Other Heroku tutorials:
- What is Heroku for Developers (Benefits, how it works and key concepts)
- Deploy Simple Spring Boot Project to Heroku using Git and Heroku CLI
- Change Java version for Apps deployed on Heroku
- Deploy Spring Boot App with MySQL Database on Heroku
- How to Enable Secure Connection (HTTPS) for Heroku Apps
- How to Deploy JAR File to Heroku
- How to Deploy WAR File to Heroku
- Add Custom Domain Names for Heroku Apps