gradle –version Error: ERROR: JAVA_HOME is set to an invalid directory: /usr/local/opt/openjdk

1. Problems

appledeMacBook-Pro:~ apple$ gradle -version

ERROR: JAVA_HOME is set to an invalid directory: /usr/local/opt/openjdk

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

2. Solution
vim /usr/local/bin/gradle

#!/bin/bash
#JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home}" exec "/usr/local/Cellar/gradle/7.0/libexec/bin/gradle"  "$@"
JAVA_HOME="${JAVA_HOME:-/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home}" exec "/usr/local/Cellar/gradle/7.0/libexec/bin/gradle"  "$@"

Similar Posts: