How to use OpenJDK 11 when deploying to Heroku? - java

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?

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.

Related

react native android Task :expo-modules-core:compileDebugKotlin FAILED

During the build process using npx react-native run-android I get the following error:
> Task :expo-modules-core:compileDebugKotlin FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 1 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.
681 actionable tasks: 665 executed, 16 up-to-date
e: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
at org.jetbrains.kotlin.com.intellij.core.CoreLanguageLevelProjectExtension.<init>(CoreLanguageLevelProjectExtension.java:26)
...
About my project:
It was 1st developed using expo sdk, then ejected (by other developer), I cloned the repo on my local machine and tried the following steps to build and run the app:
git glone https://...
cd repo
git checkout -b my_feature_branch
yarn cache clean
yarn install
npx react-native run-android
Then after these steps, I got some build errors but I resolved them, next, I encountered the build error (mentioned above), to solve this I tried the following solution https://stackoverflow.com/a/70675546/11685381 but no luck, I'm still stuck with this error, it's been 3 days since I'm stuck.
My config:
OS: Ubuntu 20.04
local.properties:
sdk.dir = /home/user/Android/Sdk
ndk.dir = /home/user/Android/Sdk/ndk
java --version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
gradle version in project/android/gradle/wrapper/gradle-wrapper.properties => gradle-7.3-all.zip
Can someone please help me out here? Thanks in advance!

upgraded maven pom.xml from java 8 to 13. how can i run upgraded maven project on both java 8 and 13 installed machines

When am trying to maven build to create a fat jar an upgraded project in java 8 installed machine getting following error
Waiting for Jenkins to finish collecting data[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project : Fatal error compiling: invalid target release: 13 -> [Help 1]
You can't compile against a target Java version of 13 when using Java 8. Either upgrade your JDK, or change your target compiler level to 1.8.

Gradle on macOS Hight Sierra - Java 9

I update java to the lasted version e then I following this guide to install grade using Homebrew:
gradle installation guide
When the gradle installation is finished, I tried to launch gradre using the command: grade by command line but appear this error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '9.0.1'.
How can I fix this problem?
It is a Gradle bug has been fixed in version 4.2.1:
https://github.com/gradle/gradle/commit/d9c35cf9d74c102641fcfe0bb7bf622791a96caf

Error:Gradle: Execution failed for task in Intellij 2017 running on Ubuntu 16.04

I'm using IntelliJ 2017 Ultimate version in Linux Ubuntu 16.04. I have created my first Android application here and it gives me this error:
Error:Gradle: Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
I am using java version 1.8.0_131 and Android SDK API 24.
Java projects work properly and I used the same method of creating the Android Application in Windows 7 and it works properly.
I will be thankful, if you can help me in this matter.

why is my gradle build failing but gradlew build is successsful?

I have a gradle project that I am trying to build.
when I execute gradle clean build, it fails with the following error message
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':FacebookUpdateDependencies'.
> Could not resolve all dependencies for configuration ':compiler'.
> Could not resolve com.company.facebook:compiler:1.2+.
Required by:
::1.0
> Could not resolve com.company.facebook:compiler:1.2+.
> Failed to list versions for com.company.facebook:compiler.
> Unable to load Maven meta-data from http://mycompanynexus/compiler/maven-metadata.xml.
> Could not GET 'http://mycompanynexus/compiler/maven-metadata.xml'. Received status code 500 from server: Internal Server Error
However, when I tried
./gradlew clean build the build is successful.
why the build fails in the former and not the latter?
here is revelant portion of build.gradle
task wrapper(type: Wrapper) {
gradleVersion = '2.11'
}
EDIT
local$: gradle -v
------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------
Build time: 2016-04-25 04:10:10 UTC
Build number: none
Revision: 3b427b1481e46232107303c90be7b05079b05b1c
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Mac OS X 10.11.1 x86_64
local$ ./gradlew -v
------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------
Build time: 2014-04-29 09:24:31 UTC
Build number: none
Revision: a831fa866d46cbee94e61a09af15f9dd95987421
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Mac OS X 10.11.1 x86_64
I just noticed that the wrapper version is 1.12 and not 2.12. That is, there is a very large version difference between the wrapper and the installed version of gradle. There have probably been many incompatible changes to the different gradle plugins over the last 2 years, which may lead to the build problems you observe.
As already mentioned the gradle wrapper is a separate version of gradle that resides in the gradle/wrapper folder of your project. The wrapper is only built/updated, when executing the wrapper task in your project (gradle wrapper). That is your project's wrapper has not been updated for the last 2 years or has been created with the wrong version initially (1.12 instead of 2.11).
Given the above it's hard the tell what is actually causing the build to fail - apart from the incompatibilities between gradle 1.12 and 2.13. But this version mismatch is probably the root cause of your problem.
Most likely your project won't built anymore using the wrapper once you regenerated the wrapper with version 2.11 (the version mentioned in the build file), as 2.11 is likely to be incompatible to 1.12 as well...
This tells you that your Gradle version 2.11 will be used when gradlew command is invoked instead of the one installed on system. Always run gradlew command as it ensures your build is run against the gradle version it is supposed to, you are never required to install the correct version of gradle and really speeds up the build time.
Here is an excerpt from Gradle Wrapper definition:
Most tools require installation on your computer before you can use them. If the installation is easy, you may think that’s fine. But it can be an unnecessary burden on the users of the build. Equally importantly, will the user install the right version of the tool for the build? What if they’re building an old version of the software?
The Gradle Wrapper (henceforth referred to as the “Wrapper”) solves both these problems and is the preferred way of starting a Gradle build.
If a Gradle project has set up the Wrapper (and we recommend all projects do so), you can execute the build using one of the following commands from the root of the project:
./gradlew (on Unix-like platforms such as Linux and Mac OS X)
gradlew (on Windows using the gradlew.bat batch file)
Each Wrapper is tied to a specific version of Gradle, so when you first run one of the commands above for a given Gradle version, it will download the
corresponding Gradle distribution and use it to execute the build.

Categories