'VSCode error 'Java Home is different' when trying to develope on Mac

I am trying to develope my java app on Mac usig Gradle + openjdk. I have installed the openjdk using homebrew.

When I open my workspace in VSCode, I get the following error...

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-5.4.1-bin.zip'.
The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch: 
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/opt/homebrew/opt/openjdk@11,daemonRegistryDir=/Users/myusername/.gradle/daemon,pid=13909,idleTimeout=null,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=utf8,-Duser.country=CA,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=2e7a0e3f-ef48-46c7-add0-0230d33c95eb,javaHome=/opt/homebrew/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home,daemonRegistryDir=/Users/myusername/.gradle/daemon,pid=13916,idleTimeout=10800000,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=utf8,-Duser.country=CA,-Duser.language=en,-Duser.variant]

When I run echo $JAVA_HOME I get the following output...

/opt/homebrew/opt/openjdk@11


Solution 1:[1]

Did you try to set the setting java.import.gradle.java.home in VS Code with your expected javaHome path?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shi Chen