I have a simple Gradle project in Eclipse and using Buildship.
Inside build.gradle I print out java version like this
println System.getProperty('java.home')
In Eclipse, I have only one JRE in Installed JREs (that points to C:/Java/JDK8). JavaSE-1.8 in Execution Environments has only a single compatible JRE - the one pointing to C:/Java/JDK8. My JAVA_HOME also points to C:/Java/JDK8.
When I run any Gradle task from Eclipse, Gradle is taking another JDK on my system (moreover, only JRE). The only way I can convince Buildship to use my wished JDK is to go to Run Configurations and in Java Home tab specify the JDK again. But this is super inconvenient to do it for every Run configuration separately.
When I execute Gradle from command line, it takes the proper one from JAVA_HOME. The problem occurs only when using Buildship.
Is there any way, how I can set Java home in Buildship globally?
Instead of relying on JAVA_HOME (which doesn’t work in the IDE as you have found out), you can use org.gradle.java.home in the gradle.properties inside your Gradle user home directory. That will apply to both command line and IDE builds.
This works, it’s quite clumsy though. Now I need to tell all developers to put it there and maintain it every time there is a new JDK update. Moreover, it’s confusing when I pick different JDK on Eclipse but Gradle executes with the one specified in gradle.properties.
The question is, why Gradle is not started with JRE I choose in Eclipse?
Are there any plans to fix this?
Gradle is started with the JRE/JDK that Eclipse is started with if you don’t specify anything in your gradle.properties.
I don’t yet understand what the difference is between putting the right java home in gradle.properties and putting it in the Eclipse configuration. Both would have to be updated if you change your Java home.
It’s an old entry, I know. But hits my problem. To answer your question, why gradle.properties is not the right place to put specific java homes into it: gradle.properties is in version control. It will be used by all developers of the project and also in Jenkins/CI builds. The configuration of java is done elsewhere - in Jenkins or in eclipse Installed JREs preferences. Now I have the problem, that gradle starts with Java 11 (the java eclipse starts with), while the JRE of the project is still Java 8. Some of the plugins fails with Java 11. So the whole “Refresh Task For All Projects” in the Gradle Task view fails already, leaving all projects crossed out. No way to configure “Gradle run configuration”. The only chance I have is to start eclipse with java 8.