Specifying JRE in Eclipse using Buildship does not work


(Martin Linha) #1


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?


(Stefan Oehme) #2

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.

(Martin Linha) #3

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?


(Stefan Oehme) #4

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.

(Delli Kilari) #5

You can set your own JAVA_HOME by following below…

  • Go to Gradle Task in Eclipse.
  • Right click on which gradle task you need to run and select “Open gradle run configurations”
  • Then go to JAVA_HOME tab.
  • Browse to JDK that you want to use.
  • Then apply…

Thats it, it should help…

(Shanpeng Mu) #6

works for me. thanks