Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure CLI by

With Leiningen I can connect to an nrepl server with

lein repl :connect

And it will pick up the port from the .nrepl-port file and drop me into a REPL prompt.

With clojure I am assuming I need to inject some nREPL client dependency and run the client and such, so not expecting it to be as succinct, but still, how would I do it?

2 Answers

+1 vote
by
selected by
 
Best answer

Try with this:

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -m nrepl.cmdline -c --host 127.0.0.1 --port PORT

You can get PORT number from .nrepl-port or from leiningen output when it started nREPL server.

by
edited by
Thanks. Using the same mix with the shell as I did with my answer, I get it to be fairly equivalent to `lein repl :connect`:

    clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"}}}' -m nrepl.cmdline -c --host 127.0.0.1 --port `< .nrepl-port`

A difference between this and reply and lein (which uses reply) is that those drop me into the main ns of my project, whereas this one drops me into `user`. A minor inconvenience. I am mostly curious about how reply figures out the main ns of my project...
0 votes
by

The closest I get is using reply and this mix of shell/clojure:

clojure -Sdeps '{:deps {reply/reply {:mvn/version "0.5.1"}}}' -M -m reply.main --attach `< .nrepl-port` 
by
Also, building on @sanel's answer, and utilizing that my project has the dependency on `nrepl` specified:

    clj -M -m nrepl.cmdline -c --port `< .nrepl-port`
...