Gradle with Java 17 in Unity 2022.3 UBA

Due to recent SDK updates, we now need to use Gradle 8.8 in Unity 2022.3, and consequently Java 17. We managed to set it up locally, and we are now trying to do the same in Unity Build Automation (UBA). However, we haven’t been able to change the Java version from 11 to 17.

We attempted to change the JAVA_HOME environment variable by all possible means, but it seems this does not affect how Gradle is launched.

In both the Windows and Mac build environments, we get the following:

CommandInvokationFailure: Gradle build failed.
/Library/Java/JavaVirtualMachines/jdk-11/Contents/Home/bin/java

CommandInvokationFailure: Gradle build failed.
C:\Program Files\Java\jdk1.11\bin\java.exe

To continue using Unity Build Automation (UBA), we need at least some way to run Gradle with Java 17 for Unity 2022.3.

I haven’t dug into Mac but on Windows we have an environment variable called JAVA17_HOME that points to the location of Java 17 on our Windows machines.

I haven’t validated this but if you setup a pre-export method to set the jdkRootPath to the value of JAVA17_HOME then I believe that the Editor will then build with Java 17. You could also use a pre-export method to set the JAVA_HOME environment variable to be equal to JAVA17_HOME. This should work because the pre-export method runs after we would have earlier set the jdkRootPath to Java 11.