salesforce/bazel-eclipse

JDK configuration errors: "IllegalArgumentException: external/local_jdk", "Unable to locate a Java Runtime."

plaird opened this issue · 2 comments

JDK configuration with Bazel has always been troublesome. Even in Bazel 5, there are issues.

When BEF invokes Bazel commands, it does not set JAVA_HOME. Historically, this was ok. But recent versions of Bazel/Eclipse this has become more problematic. It seems Bazel is becoming more dependent on JAVA_HOME.

>> Unable to run coursier: The operation couldn’t be completed. Unable to locate a Java Runtime.
Install a system JDK, for example brew install openjdk

>> IllegalArgumentException: external/local_jdk (DumpPlatformClassPath)
See this post and add something like the follow to your .bazelrc file:

build --define=ABSOLUTE_JAVABASE='/Users/mbenioff/dev/openjdk_11.0.10_11.45.28_x64'
build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase
build --javabase=@bazel_tools//tools/jdk:absolute_javabase

To make this better, we could set JAVA_HOME in the shell command using the configured JDK in Eclipse (if there is one) or JRE.

The other workaround is to export JAVA_HOME in a shell, and launch Eclipse from that shell.