Josh Glover
Josh Glover

Reputation: 26140

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?

Upvotes: 7

Views: 701

Answers (1)

DanLebrero
DanLebrero

Reputation: 8593

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

Upvotes: 6

Related Questions