Lately I've spent too much time dealing with a bug involving having a precise JVM (GraalVM) running my REPL, here is the breakdown of how to know precisely - and change! - the current running JVM with Emacs and Cider.
First, you can inspect the command that will be used by Cider to start the clojure REPL with the universal-argument
command.
Run M-x universal-argument
(SPC u
with Doom Emacs) then cider-jack-in
you could then edit the command before hitting ENTER
to run the edited command.
In my case my project uses the Clojure CLI and deps.edn. You should see that cider use your clojure
executable, on my machine /opt/homebrew/bin/clojure
.
If we inspect the clojure
executable we see that one-liner:
#!/bin/bash
JAVA_HOME="${JAVA_HOME:-/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home}" exec "/opt/homebrew/Cellar/clojure/1.11.3.1463/libexec/bin/clojure" "$@"
Here the JAVA_HOME is set only if there isn't already a value with variable expansion.
sdkman is a useful tool to manage different JDK, Graalvm, etc installations. When using sdkman your JAVA_HOME
environment variable will be a symbolic link to the current used one: ~/.sdkman/candidates/java/current
.
Emacs launch a subprocess with its own environment variables when starting a REPL, I did'nt manage to know what is setting my env var under MacOS (/etc/profile
, /etc/bashrc
, ~/.profile
, ~/.bashrc
, ~/.zshrc
) so in the end I change the clojure
launcher to override the JAVA_HOME with the sdkman link, and to manage my JDK version from a single place, that's to say sdkman.
In the end, my clojure launcher is the following:
#!/bin/bash
JAVA_HOME="/Users/username/.sdkman/candidates/java/current" exec "/opt/homebrew/Cellar/clojure/1.11.3.1463/libexec/bin/clojure" "$@"
Check the JVM you're in from your REPL: (System/getProperty "java.home")