This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-06-12
Channels
- # babashka (26)
- # beginners (19)
- # biff (4)
- # cider (44)
- # clerk (7)
- # clj-kondo (12)
- # clojure (25)
- # clojure-austin (9)
- # clojure-denmark (2)
- # clojure-europe (28)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (35)
- # clojure-spec (7)
- # clojure-sweden (5)
- # clojure-uk (6)
- # cursive (22)
- # datascript (1)
- # datomic (4)
- # dev-tooling (2)
- # events (3)
- # gratitude (1)
- # honeysql (30)
- # hoplon (6)
- # hyperfiddle (4)
- # malli (4)
- # missionary (3)
- # off-topic (2)
- # overtone (2)
- # pathom (21)
- # reitit (3)
- # releases (4)
- # shadow-cljs (32)
- # sql (22)
- # xtdb (8)
- # yamlscript (6)
hey all, how do I set the JDK version?
> java -version
openjdk version "22.0.1" 2024-04-16
OpenJDK Runtime Environment Homebrew (build 22.0.1)
OpenJDK 64-Bit Server VM Homebrew (build 22.0.1, mixed mode, sharing)
However, when I start cider with:
[nREPL] Starting server via /opt/homebrew/bin/clojure -Sdeps \{\:deps\ \{nrepl/nrepl\ \{\:mvn/version\ \"1.0.0\"\}\ cider/cider-nrepl\ \{\:mvn/version\ \"0.45.0\"\}\ refactor-nrepl/refactor-nrepl\ \{\:mvn/version\ \"3.9.1\"\}\}\ \:aliases\ \{\:cider/nrepl\ \{\:main-opts\ \[\"-m\"\ \"nrepl.cmdline\"\ \"--middleware\"\ \"\[refactor-nrepl.middleware/wrap-refactor\,cider.nrepl/cider-middleware\]\"\]\}\}\} -M:cider/nrepl
I can see that it's using Java 11 in the REPL buffer
nREPL server started on port 51778 on host localhost -
;; Connected to nREPL server -
;; CIDER 1.14.0-snapshot (package: 1.14.0-snapshot), nREPL 1.0.0
;; Clojure 1.11.3, Java 11
One option is to do C-u M-x cider-jack-in
(that is, jack in with a universal argument). That allows you to edit the command line where you can put JAVA_HOME=/path/to/jdk
in front, and that would set the JDK version.
Otherwise, you have to somehow set JAVA_HOME
env variable in Emacs, there are a few guides on the internet how to do that, but none of them worked for me reliably. What I do is that I set the env in the terminal shell and then launch Emacs from there so that Emacs inherits the java version I want.
I think JAVA_HOME
is set correctly, running terminal directly from emacs:
❯ echo $JAVA_HOME
/opt/homebrew/opt/openjdk
❯ java -version
openjdk version "22.0.1" 2024-04-16
OpenJDK Runtime Environment Homebrew (build 22.0.1)
OpenJDK 64-Bit Server VM Homebrew (build 22.0.1, mixed mode, sharing)
This returns the same as running from outside of emacs, so I think emacs is correctly inheriting the environment.
I've tried appending JAVA_HOME
to the nrepl start command, and I get the same result - Java 11/opt/homebrew/opt/openjdkWhat's inside that directory? It looks to me as the homebrew-installed Java does its own JDK selection under the hood.
yeah, stupid moment from my side 😅 though I still don't understand why the correct JAVA_HOME is not inherited... :thinking_face:
I think it is correct, but there is one additional layer of indirection (that relies on I don't know what) that causes the thing in /opt/homebrew/opt/openjdk
to select a different JDK
Matching Java Virtual Machines (4):
21.0.1 (arm64) " Inc." - "Amazon Corretto 21" /Users/akis/Library/Java/JavaVirtualMachines/corretto-21.0.1/Contents/Home
21.0.1 (arm64) "Oracle Corporation" - "OpenJDK 21.0.1" /Users/akis/Library/Java/JavaVirtualMachines/openjdk-21.0.1/Contents/Home
17.0.4.1 (arm64) "Eclipse Adoptium" - "OpenJDK 17.0.4.1" /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
1.8.0_382 (x86_64) "Eclipse Temurin" - "Eclipse Temurin 8" /Users/akis/Library/Java/JavaVirtualMachines/temurin-1.8.0_382/Contents/Home
hah, true 😅 Seems like a start of a nice, deep, rabbit hole 😂 I can live with universal command though, that was really helpful! 🙇 I'm sure I messed up java installs long time ago on this machine, so probably that's what's causing the pain right now
Yeah, I'd start with picking one way of installing and managing JDKs, and then extend it to Emacs. Because right now it's hard to tell who's setting your JAVA_HOME and how it later translates to the exact JDK install path.
Some people have success with SDKMAN, I personally just download tarballs and extract them to /Library/Java/JavaVirtualMachines/
. Then I have a shell function that allows me to quickly switch JAVA_HOME
between them.
I updated to the latest cider and I am getting this warning now when starting my repl:
;; Connected to nREPL server -
;; CIDER 1.15.0 (Cogne), nREPL 1.2.0-beta2
;; Clojure 1.10.1, Java 11.0.22
;; Docs: (doc function-name)
;; (find-doc part-of-name)
;; Source: (source function-name)
;; Javadoc: (javadoc java-object-or-class)
;; Exit:
;; Results: Stored in vars *1, *2, *3, an exception in *e;
;; Startup: /home/harold/bin/lein update-in :dependencies conj \[nrepl/nrepl\ \"1.2.0-beta2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.49.0\"\] -- repl :headless :host localhost
WARNING: CIDER requires cider-nrepl to be fully functional. Some features will not be available without it! (More information)
Probably some dependency version conflict in this project (the project has many dependencies). How can I start to track it down? Thanks!
Also, I am not seeing prints in the repl - probably related to the above warning?I'd start by a ps aux | grep cider
and see the cider version(s) present in your classpath
(-> (System/getProperty "java.class.path") (clojure.string/split #":") (->> (filter #(clojure.string/includes? % "cider"))))
from the repl should do it
Both very helpful ideas! Indeed, it appears cider-nrepl is not on the classpath. :thinking_face:
And it is on the classpath in the case of a new project (`lein new app foo`). So something with this project in particular.
Ooooo, if I switch the new (foo) project to clojure 1.10.1 I start getting the warning.
Nope https://docs.cider.mx/cider/about/compatibility.html#clojure Not immediately obvious to me why this would happen if you don't have Lein plugins around. @U06PNK4HG anything comes to mind?
Yup - also confirmed: changing the clojure dep to 1.11.3
in the real project also gets rid of the warning (and print starts working again as well)
> Cool, I'm happy to make an issue on the cider repo as well if that would be helpful.
That would be welcome.
Before that, you can try /home/harold/bin/lein update-in :dependencies conj \[nrepl/nrepl\ \"1.2.0-beta2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.49.0\"\] -- repl :headless :host localhost
(i.e. the same command emitted by CIDER) from the CLI. Does cider-nrepl disappear from the classpath too in that case?
Also, are you on Lein latest? It has had more changes than usual in the last year or so I think.
Ah!
$ /home/harold/bin/lein update-in :dependencies conj \[nrepl/nrepl\ \"1.2.0-beta2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.49.0\"\] -- repl :headless :host localhost
Warning: cider-nrepl requires Clojure 1.10.3 or greater.
Warning: cider-nrepl will not be included in your project.
https://codeberg.org/leiningen/leiningen/releases/tag/2.11.2 is latest, probably it includes a more recent Clojure by default and solves the issue
Thanks so much for your help @U45T93RA6 and @U11BV7MTK, I learned a lot. 🙇
Cheers. Normally I start cider-nrepl from the CLI as it is more debuggable. And it persists in case Emacs crashed/froze
That's a neat idea, makes sense that there are some tradeoffs for the convenience of letting cider-jack-in
do it.
@U11BV7MTK @U0F7WES86 BTW, you can also press ,
in the REPL and select classpath
.
I just randomly bumped into this same issue when debugging why some old project (using clojure 1.10.0) had trouble running tests with cider
This issue has been fixed in master, need a release of cider-nrepl now. https://github.com/clojure-emacs/cider-nrepl/pull/883