intellij-ideaclojureread-eval-print-loopcursive

How to run Clojure REPL using IntelliJ and Cursive plugin


I am desperately trying to set up a working environment for Clojure 1.12.0.1488, using IntelliJ 2024.3, Cursive's plugin 2025.1.1-343 and openJDK 24.

I am using VoidLinux based on kernel 6.12.28_1, nushell 0.103.0 and kitty terminal 0.41.0.

I have a project named mytuto (marked as rooted folder, hence the tiny blue icon), which merely contains a deps.edn file consisting of:

{
 :aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.5"}}
                   :exec-fn rebel-readline.tool/repl
                   :exec-args {}
                   :main-opts ["-m" "rebel-readline.main"]}}
 :deps {clojure.java-time/clojure.java-time {:mvn/version "1.4.3"}
        org.clojure/clojure {:mvn/version "1.12.0"}}
}

and a src/hi.clj which contents are as follow:

(ns hi)

(defn -main []
  (println "hi people"))

I do have edited a Run configuration, of the Clojure REPL Local type, like so: Edit configuration for Clojure REPL

where the key component is simply adding -M:rebel -m hi

I did try using openJDK 23 and 24, and both nREPL and clojure.main as a REPL type but to no avail.

I also rebuilt the project, then invalidated the caches and restarted IntelliJ each time a tried altering a setting or editing the dependencies or source code.

Now when I try to run the namespace hi using Shift + F10, it consistently reports the following error:

Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main

Process finished with exit code 1

The full log version including both errors linked to clojure.main REPL type and nREPL one is included here:

Starting clojure.main REPL...
/usr/lib/jvm/openjdk24/bin/java -javaagent:/usr/lib/intellij-idea/lib/idea_rt.jar=39857 -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /home/aurele/dev/clojure/mytuto/src clojure.main -M:rebel -m hi

Process finished with exit code 1

Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main

Process finished with exit code 1
REPL startup failed:
No nREPL connection details received

IntelliJ error output for the Clojure REPL

There are also some weird warnings highlighting that ns, defn and println can not be resolved, indicating me that clojure keywords are not even recognized.

Here is the related screenshot for good measure: IntelliJ keywords not resolved

Running clojure -M -m hi does print hi people as expected but trying to run clojure -M:rebel -m hi reports that an error occured due to a unknown option: "-m"`, as seen in the subsequent screen shot:

IntelliJ REPL error

I would be grateful if someone could help me as it would allow me to actually start learning the language and move forward in my career path.

Someone told me that my command is equivalent to clj -M -m rebel-readline.main -m hi, so I am passing -m hi as command-line arguments to Rebel Readline itself (which it rejects). But I still lack knowledge to fix it by myself.

EDIT: Accessing the Action search dialog brings no thing when typing Add as Clojure Deps Project as showed in the subsequent screen shot: IntelliJ search action empty

However, typing merely Clojure Deps causes 2 results to appear. When the latter is irrelevant for our purpose, the former do have a possibly interesting setting: IntelliJ Search Action results

deps.clj version was set with 1.12.0.1530 whereas my actual Clojure installed version is 1.12.0.1488. I did change it to match my installation, and applied it but that not solved the matter at hand :-/

IntelliJ Search Action Clojure Deps

Finally, I catched a error message that could well be a serious piece of information, given the appropriate know-how (which I have not), in the Run/set configuration related to the Clojure REPL: Edit config error message

I had also modified the parameter into -A:rebel like suggested.

EDIT: I would like to add, in case it would help others facing that same kind of issue, that adding :paths ["src"] into the deps.edn file fixed the non-detection by Cursive of src folder as the source tree, that messed up the name's resolution of namespace entirely.


Solution

  • Why are you trying to use rebel-readline? Cursive has its own REPL window that isn't a normal terminal input, so the use of rebel-readline doesn't really make sense.

    I'd recommend starting from scratch, since I'm unsure if you didn't make things complicated for yourself with all the options you tried. You can keep all the sources but overwrite the IntelliJ/Cursive project. Just go via "File -> New -> Project from Existing Sources". Then navigate to the folder and select the deps.edn file.

    Once the project is created go into the run configuration and add a Clojure REPL -> Local configuration (via +). Then select nREPL and Run with Deps, do not add any options. So do not activate the :rebel alias in any way. You can keep it in deps.edn but just don't make Cursive use it.

    Once you click run you should have a working REPL window.