lein repl starts in wrong namespace

clojure, leiningen

Solution

When lein repl task runs, it will look up the ns to switch to in this order of preference:

- ns specified in the :init-ns of the :repl-options

- ns specified :main

- user ns

In your case, try adding:

:repl-options {:init-ns user}

to your project.clj

Problem

TLDR; `lein repl` starts in the namespace defined by `:main` in `project.clj`, instead of `user`, as desired. Details I have a Leiningen project which is deployed as a command-line application in an uberjar, so I can run it like so: ``` java -jar my-app-1.0-standalone.jar --some --args ``` I also have a `dev/user.clj` to give me a nice REPL environment, as described here. My `project.clj` looks like this: ``` (defproject my-app "1.0" :main my-app.cli :aot [my-app.cli] :profiles {:dev {:source-paths ["src" "dev"]}}) ``` When I start my REPL, either with `lein repl` from the command line or `M-x cider-jack-in` from Emacs, I am in the `my-app.cli` namespace, rather than `user`. If I remove `:main my-app.cli` from `project.clj`, my REPL starts in the `user` namespace as I'd expect, but clearly this breaks my uberjar. Any ideas?

Original source