I was looking for a way to invoke an nREPL server using clojure -X
and specify extra dependencies and middleware in separate aliases which would be composed together on the command line.
For context: nREPL middleware are specified as a list of functions/runtime-resolved symbols, so ideally there would be some mechanism for each alias in the deps.edn to specify their own vector-of-middleware and have them concatenated in the order which the aliases were listed on the command line. (See below for concrete demonstration of this)
Unfortunately I couldn't find a satisfactory way of achieving this via the clojure CLI - the issue is that :exec-args
maps from different aliases are simply merged, with latter values overriding earlier ones. The clojure.org reference mentions deep merging but this appears to be a doc error.
(Note that the widespread use of -M
for this use case does not afford any way of composing command-line string args, forcing each alias to couple together all middleware and dependencies.)
Of course there shouldn't exist some magic set of semantics for merging exec-arg
values (vectors => concat, maps => merge etc.)... Nevertheless there might be a usability gap to fill here, letting users specify their own merging semantics declaratively rather than having to resort to custom-coded task runners .
An example of how this would look like from the command line, given concat
semantics for the :middleware
arg:
$ clojure -X:nrepl
Starting nREPL server with: nil
$ clojure -X:nrepl :port 1234
Starting nREPL server with: {:port 1234}
$ clojure -X:cider:nrepl :port 5678
Starting nREPL server with: {:port 5678 :middleware [cider.nrepl/cider-middleware]}
$ clojure -X:portal:cider:nrepl
Starting nREPL server with: {:middleware [portal.nrepl/wrap-portal, cider.nrepl/cider-middleware]}
$ clojure -X:cider:cljr:portal:nrepl
Starting nREPL server with: {:middleware [cider.nrepl/cider-middleware, refactor-nrepl.middleware/wrap-refactor, portal.nrepl/wrap-portal]}
see this conversation in Slack thread for more context:
https://clojurians.slack.com/archives/C6QH853H8/p1711461045176759