In Gradle, is there a way to install the JDK in Eclipse Default?

I integrate gradle build files into our eclipse development environment, which supports multiple JDKs. While most developers have several versions installed, it would be correct to use the “standard JRE”, as shown on the page “System Preferences → Java-> Installed JREs”.

Is there any way to have gradle set JAVA_HOME (or "org.gradle.java.home" ??) to this? If not, any suggestions on a better way to do this for such a development team? This is not a problem for just one person, she is trying to find a common approach that will scale across the whole group of us who are looking for me!

thanks!

+7
source share
3 answers

I'm still not quite sure what you are asking for, but here are a few different solutions.

  • If you want to make your code (in Gradle and Eclipse) so that the bytecode is compatible with a specific version of Java, use something like this. This does not change the version of Java that Gradle or Eclipse uses at compile time, it simply makes the end result "bytecode compatible" with the version you specify. The options that Luis mentions by default for values ​​set at a more general level of the Java plugin.

    sourceCompatibility = '1.6' //or '1.5' or '1.7', etc. 
  • By default, the Gradle Eclipse plugin will generate the next entry in your .classpath file. I believe this always indicates the default value that you specify in Eclipse, but I could be wrong.

     <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/> 

    If you want to change what is in this container, select the one you are looking for in Eclipse, and then look in the .classpath file for the correct container value. Then you can specify it in the assembly file:

     eclipse.classpath.containers 'whatever the container value is' 
  • However, if you want to change the JAVA_HOME that Gradle works with to match the default selected in Eclipse, I think it will be difficult for you. I am not sure if there is a convenient place to find this value programmatically. Perhaps you could install it from the opposite direction. Ask developers to install JAVA_HOME according to their Eclipse standard. They can then reference the JAVA_HOME environment variable in the Eclipse configuration for their JRE.

+10
source

if you have different versions of jdk it's easy

 apply plugin: 'java' apply plugin: 'eclipse' eclipse { jdt { //if you want to alter the java versions (by default they are configured with gradle java plugin settings): sourceCompatibility = 1.6 targetCompatibility = 1.5 

Now, if you use different JVM 1.6.XX and want to target specific, I'm not sure.

+4
source

Try installing the "Gradle IDE Package" from the Eclipse Marketplace. I am in Eclipse Luna and see this option in the menu "Settings> Gradle> Arguments":

Eclipse Gradle Plugin Arguments dialog

You can verify that the JRE you selected was used with the file command, as indicated in this answer .

+1
source

All Articles