I'm really sorry to ask this question, since there's already multiple questions about this exact topic. I tried everything I found so far, but nothing seemed to work.
We build our project with Gradle and it's running on Java 8. I had to install Java 17 for a new project I'm working on and since then Gradle keeps using Java 17, when it shouldn't.
My JAVA_HOME is set to 1.8 and the default java is also 1.8.
After reading loads and loads of topics here, I also tried setting org.gradle.java.home in the gradle.properties file.
But neither on project-level nor on user-level; gradle keeps using 1.17.
Now I also installed jenv to define an explicit java version on my project-folder. And even though the local, but also the global, java version is set to 1.8 it doesn't change for gradle.
It keeps defaulting to /usr/lib/jvm/java-17-openjdk-arm64.
The only way it seemed to work, is when I run the gradle command with the argument to set the system variable
(./gradlew build -Dorg.gradle.java.home=/path/to/jdk)
Has anyone had a similar problem or knows, why gradle isn't using the java.home I declared in the gradle.properties?
I know that gradle reads the project-level gradle.properties, since it includes user/password for our maven repository.
Edit (comment of @joachim-sauer):
- I launch gradle via terminal and use a wrapper, so the exact command is
./gradlew [command] which javaoutputs to/home/user/.jenv/shims(due to the installation of jenv), whereasjava -versionoutputsjava version "1.8.0_181"- I didn't explicitly enable or disable daemon-mode, so I guess by default it's enabled?
- gradle fails to build, the error occurs due to a missing package, which was removed since java 11. I also tried logging it, adding
println(System.getProperty("java.home")to mybuild.gradle. This also outputs/usr/lib/jvm/java-17-openjdk-arm64
Best regards 3m7ecc