nREPL Middleware Setup

You can skip this section if you don’t plan to use cider-connect or don’t care about the advanced functionality that requires cider-nrepl.

Much of CIDER’s functionality depends on its own nREPL middleware. cider-jack-in (C-c C-x (C-)j (C-)j) automatically injects this middleware and other dependencies as required. But if you prefer a standalone REPL, you will need to invoke cider-connect instead of cider-jack-in and manually add the dependencies to your Clojure project (explained in the following sections).

Setting Up a Standalone REPL

Using Leiningen

Use the convenient plugin for defaults, either in your project’s project.clj file or in the :repl profile in ~/.lein/profiles.clj.

:plugins [[cider/cider-nrepl "0.59.0"]]

A minimal profiles.clj for CIDER would be:

{:repl {:plugins [[cider/cider-nrepl "0.59.0"]]}}
Be careful not to place this in the :user profile, as this way CIDER’s middleware will always get loaded, causing lein to start slower. You really need it just for lein repl and this is what the :repl profile is for.

Using tools.deps

You can add the following aliases to your deps.edn in order to launch a standalone Clojure(Script) nREPL server with CIDER middleware from the commandline with something like clj -A:cider-clj. Then from emacs run cider-connect or cider-connect-cljs.

  :cider-clj {:extra-deps {cider/cider-nrepl {:mvn/version "0.59.0"}}
              :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

  :cider-cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.339"}
                            cider/cider-nrepl {:mvn/version "0.59.0"}
                            cider/piggieback {:mvn/version "0.6.1"}}
               :main-opts ["-m" "nrepl.cmdline" "--middleware"
                           "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}
the suggested ClojureScript setup is apt for e.g. library development, but not for frontend development. For those cases, you may want to check out our shadow-cljs or figwheel setups instead.

Using Launchpad

[Launchpad](https://github.com/lambdaisland/launchpad) lets you start a nREPL server from the command line, while including the middleware your editor requires and providing additional developer conveniences.

In your project, create bin/launchpad. The only requirement is [babashka](https://babashka.org/).

#!/usr/bin/env bb

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.lambdaisland/launchpad {:mvn/version "RELEASE"}}})

(require '[lambdaisland.launchpad :as launchpad])

(launchpad/main {})

Now bin/launchpad --emacs will start a Clojure process, and connect Emacs to your REPL, and include the cider-nrepl middleware.

To load additional middleware, configure it inside bin/launchpad

;; <snip> ... as before ... <snip>
(launchpad/main {:middleware [your.custom/nrepl-middleware]})

See bin/launchpad --help or the [README](https://github.com/lambdaisland/launchpad) for more info.

Using Gradle

Make sure you’re using Clojurephant 0.4.0 or newer.
build.gradle
dependencies {
  devImplementation 'nrepl:nrepl:1.7.0'
  devImplementation 'cider:cider-nrepl:0.59.0'
}

tasks.named('clojureRepl') {
  middleware = ['cider.nrepl/cider-middleware']
}

You can then launch the nREPL server from the command line via: ./gradlew clojureRepl.

For more information, see the Clojurephant docs.

Using Maven

This section is currently a stub. Contributions welcome!

Using Embedded nREPL Server

If you’re embedding nREPL in your application, you’ll have to start the server with CIDER’s own nREPL handler.

(ns my-app
  (:require [nrepl.server :as nrepl-server]
            [cider.nrepl :refer (cider-nrepl-handler)]))

(defn -main
  []
  (nrepl-server/start-server :port 7888 :handler cider-nrepl-handler))

It goes without saying that your project should depend on cider-nrepl.

CIDER and cider-nrepl projects are co-developed, but are not released in a lock-step — they have differing versions. Usually, any recent version of cider-nrepl should be (mostly) compatible with a recent version of CIDER. You can check the required version of cider-nrepl for your version of CIDER by looking at cider-required-middleware-version. See also the compatibility matrix.