Marcello DeSales
Marcello DeSales

Reputation: 22329

How to make Gradle 2.x, Gradle 3.x, Gradle 4.x to run with Java 9?

When using Gradle 2.x, 3.x, and 4.x that only supports Java 8, the gradle runtime does NOT run. I just installed JDK 9 on my MAC and now Gradle 2.x does NOT run. Any versions before 4.2.1.

$ gradle
$ 

Nothing happens... How to fix that?

Upvotes: 1

Views: 134

Answers (1)

Marcello DeSales
Marcello DeSales

Reputation: 22329

According to https://blog.gradle.org/java-9-support-update, Java 9 support for Gradle came to Gradle 4.2.1.

After installing Java 9, you will have it by default in your system:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    9.0.1, x86_64:  "Java SE 9.0.1" /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
    1.8.0_131, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home

At this point, you need to find the Gradle executable and change the JAVA_HOME to point to your Java 8 version because you still have it installed. Change the binary to define the JAVA_HOME to point to the Version 8 version.

~ ⌚ 22:54:20
$ which gradle
/usr/local/bin/gradle

~ ⌚ 11:19:12
$ vim /usr/local/bin/gradle

#!/usr/bin/env bash

##############################################################################
##
##  Gradle start up script for UN*X
##
##############################################################################

JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

After this, Gradle will work again!

$ gradle --version

------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------

Build time:   2016-04-25 04:10:10 UTC
Build number: none
Revision:     3b427b1481e46232107303c90be7b05079b05b1c

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Mac OS X 10.12.6 x86_64

Upvotes: 1

Related Questions