Setting org.gradle.java.home in gradle.properties to an environment variable

I need every project to be able to use a different version of Java. Since developers in our team all installed different versions of Java in various directories, we have an environment variable JAVA_HOME_1_8 which abstracts this out.
The last thing that’s left to do is to set org.gradle.java.home in gradle.properties to JAVA_HOME_1_8 environment variable.

I tried: org.gradle.java.home="${System.env.JAVA_HOME_1_8}" with many variations (with or wo quotation marks, same for $, etc.)

Any help would be greatly appreciated!

Thanks,

Valentin

We have similar variables, but JAVA8_HOME and so on.
We just adjusted the gradlew scripts to use these instead of JAVA_HOME.
Nowadays I would simply use Java Toolchains feature though.

Hi Bjorn,

Can you give me an example of how you did that?

Thanks,

Valentin

It’s Björn or Bjoern, not Bjorn. :wink:

The changes depend on what you want.
By default the wrappers search in JAVA_HOME if set and search in PATH if no set.
For our build we wanted to force using JAVA8_HOME, so we also removed the search in PATH and enforce JAVA8_HOME being set.
Your requirements might be different.

Also instead of manipulating the wrapper, as you have to redo this on every wrapper generation, you could also have a wrapper-wrapper that sets JAVA_HOME to the value of your variable and then calls the actual wrapper script, then is the script your colleagues have to call.

Hi Bjorn,

That is exactly what I seem to be unable to do! If you look at the original post I was saying that I can’t set org.gradle.java.home to an environment variable. In this case is JAVA_HOME_1_8 but could be anything.

Do you know how one can do that?

Thanks,

Valentin

Didn’t I just tell you that my name is not Bjorn? >:-(

That is exactly what I seem to be unable to do! If you look at the original post I was saying that I can’t set org.gradle.java.home to an environment variable.

And that is not the least what I suggested.
I said create a wrapper-wrapper that sets JAVA_HOME to JAVA_HOME_1_8 and then calls the real wrapper.

You realize I don’t have that character on my keyboard, don’t you?

grafik

I also don’t call you Falentin Meyer. :wink: