How To Define a Specific Java Home for Gradle

By default, Gradle uses the JDK defined in the JAVA_HOME environment variable or in the PATH. If you want to use a different JDK without changing the default JDK of your system, you can define the property in the Gradle Properties. Gradle Properties can be defined in the following locations, sorted by the highest priority:

  • command line, as set using -D.
  • in the GRADLE_USER_HOME directory (defaults to $USER_HOME/.gradle).
  • in the project directory, then its parent project directory up to the build root directory.
  • in the Gradle installation directory.

If an option is configured in multiple locations, the first one found in any of these locations wins. Therefore, if you want all your Gradle project to use a different JDK than the system default JDK, you can add the following property in the file $USER_HOME/.gradle/"C:\\path\\to\\the\\jdk"