简体   繁体   中英

How can I run lein repl outside of a project?

I spent some time last night messing with my leinigen profiles.clj to get rid of all the errors that were being printed when starting cider in my project. Today I went to start a repl from the terminal (I like to keep one open while I work) but it didn't work. I thought it was a cider issue so I tried it from Emacs but even in Emacs if I'm not in a project the repl won't start.

Here's the error:

Error loading refactor-nrepl.middleware: clojure.lang.ArityException: Wrong number of args (4) passed to: StringReader, compiling:(abnf.clj:186:28)
Exception in thread "Thread-4" java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context, compiling:(NO_SOURCE_PATH:0:0)
...
Caused by: java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context

My ~/.lein/profiles.clj

{:user {:plugins [[lein-try "0.4.3"]
                  [refactor-nrepl "1.1.0"]
                  [cider/cider-nrepl "0.9.1"]]
        :dependencies [[org.clojure/tools.nrepl "0.2.12"]
                       [acyclic/squiggly-clojure "0.1.4"]
                       ^:replace [org.clojure/tools.nrepl "0.2.12"]
                       [refactor-nrepl "1.1.0"]]}}

The versions of things when cider starts in a project

; CIDER 0.9.1 (Java 1.8.0_45, Clojure 1.7.0, nREPL 0.2.12)

I'm still pretty new to Clojure, Leinigen, Emacs, etc so I'm not sure why everything above made made my cider errors go away but it did. The cider errors I was getting were having to do with the nrepl version being too low and not having certain things installed (like refactor-nrepl).

When starting a repl from lein using lein repl , it really wants to run in a lein project dir. I keep an empty lein project named clj around in my home dir for this purpose. That way, my common dependencies are already there in the project.clj file, and lein is pre-configured just the way I like it.

You can start lein repl in an empty dir, but you get 10-20 error messages each time before it starts.

Another way is to use the plain repl built into the clojure jar file:

~/dummy > cp /home/alan/.m2/repository/org/clojure/clojure/1.8.0-RC1/clojure-1.8.0-RC1.jar .   
~/dummy > d *
-rw-rw-r-- 1 alan alan 3935726 Nov 19 14:11 clojure-1.8.0-RC1.jar
~/dummy > java -jar clojure-1.8.0-RC1.jar 
Clojure 1.8.0-RC1
user=> 

As you can see, I created an empty directory named dummy and copied in the clojure-*.jar file. You can then run it with the syntax java -jar xxx.jar and it will fire up a repl completely independently of lein.

I also just keep a scratch project which I use for quick/simple repl sessions. There is a lien-oneoff plugin which is supposed to make it easy to work with simple single file lein projects which might be useful.

The other thing you could do is setup a boot config for basically getting a repl up to work with

what is your lein version, I am use 2.5.3 , I can start lein repl anywhere.

Shell:~ >: lein repl
nREPL server started on port 52343 on host 127.0.0.1 - nrepl://127.0.0.1:52343
REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.7.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_60-b27
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> Bye for now!
Shell:~ >: lein version
Leiningen 2.5.3 on Java 1.8.0_60 Java HotSpot(TM) 64-Bit Server VM

Shell:~ >: cat .lein/profiles.clj 
{:1.2 {:dependencies [[org.clojure/clojure "1.2.0"]]}
 :1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
 :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}

 :user {:plugins [[lein-immutant "2.0.0-alpha2"]
                  [lein-clojars "0.9.1"]
                  [lein-ancient "0.5.5"]
                  [lein-kibit "0.0.8"]
                  [lein-try "0.4.3"]
                  [venantius/ultra "0.2.0"]]
        :ultra {:color-scheme :solarized_dark}}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM