lein repl starts in wrong namespace
Asked Answered
N

1

7

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?

Nodus answered 13/7, 2014 at 7:11 Comment(0)
C
6

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

Carty answered 13/7, 2014 at 9:33 Comment(2)
Should this still work? I just tried it in Leiningen 2.7.1 under Clojure 1.9.0-beta2, and I'm getting this error: Could not locate user__init.class or user.clj on classpath. It does start in the user namespace, but there's a big stack trace before it gets there.Minier
@Ben Kovitz: try creating src/user.clj. I can reproduce your error without it, and when I create user.clj, I get no error.Quadrature

© 2022 - 2024 — McMap. All rights reserved.