1

I am trying to deploy a Java application to Heroku targeting OpenJDK 11. I've added a system.properties file to the root of my application with the following content, as per Heroku instructions:

java.runtime.version=11

However, when I deploy, I get the following Gradle error:

Gradle app detected
-----> Installing JDK 1.8... done
-----> Building Gradle app...
-----> executing ./gradlew jar
       Downloading https://services.gradle.org/distributions/gradle-4.10-all.zip

Welcome to Gradle 4.10!

[Gradle highlights]

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

How can I get Heroku to detect and use the correct Java version?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
junglie85
  • 1,243
  • 10
  • 30
  • It looks like you might be using an old version of Gradle, but I don't think you can upgrade it yourself on Heroku. [Which stack are you using](https://devcenter.heroku.com/articles/stack#viewing-which-stack-your-app-is-using)? – ChrisGPT was on strike Dec 17 '18 at 13:21
  • It's a standalone jar that I want to run as a HTTP server. I'm using Gradle 4.10.2. – junglie85 Dec 17 '18 at 14:13
  • Gradle didn't support JDK 11 until version 5.0, released on November 26. I think you'll have to upgrade. If that works I can add a proper answer below. – ChrisGPT was on strike Dec 17 '18 at 14:30
  • Interesting, since it works locally with 4.10.2. I'll see if changing that makes any difference. – junglie85 Dec 17 '18 at 14:37
  • Make sure you upgrade the wrapper by running `./gradlew wrapper --gradle-version 5.0` and `git add . && git commit`. This will make sure Heroku uses the Gradle version you use locally. – codefinger Dec 17 '18 at 17:47

1 Answers1

2

Gradle didn't officially support JDK 11 until version 5.0 (released November 26, 2018). Upgrading to that version or later should fix the issue.

See also this similar question about Java 9 support.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • This may be true, but Heroku should still have installed JDK 11 (instead of `Installing JDK 1.8`). Make sure you have the `system.properties` file checked into Git once Gradle is ready for JDK 11. – codefinger Dec 17 '18 at 17:44
  • "Make sure you have the `system.properties` file checked into Git once Gradle is ready for JDK 11"—yes, definitely. Otherwise Heroku will never see it. – ChrisGPT was on strike Dec 17 '18 at 18:22
  • This worked for me as well. I created a system.properties file with java.runtime.version=13 and snip-snap, easy peasy. Thank you! – Jason Buchanan Mar 23 '20 at 19:38