Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lein repl starts in wrong namespace

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?

like image 402
Josh Glover Avatar asked Jul 13 '14 07:07

Josh Glover


1 Answers

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

  1. ns specified in the :init-ns of the :repl-options
  2. ns specified :main
  3. user ns

In your case, try adding:

:repl-options {:init-ns user}

to your project.clj

like image 50
DanLebrero Avatar answered Sep 28 '22 14:09

DanLebrero