3

This is asking for help regarding the same question as How to change Clojure or Lein's Clojure default version?

but is not an answer to that question. Should I have nevertheless have written it as an answer under that thread?

Specifying a Clojure version to be used when the "(lein repl)" command is issued outside of a project directory seems to be a natural thing to want. Of course there may be good design reasons for not allowing it, but do you think an error message like the following,

to be displayed when Leiningen detects that the ~/.lein/profiles.clj (or other relevant profile files) specify a different Clojure version from the one hard coded into Leiningen,

would be a good idea?

"specifying the Clojure version to be used with certain software, such as tools.nrepl and clojure-complete, is only allowed when this command is issued within a project directory"

A lot of people apparently have spent a lot of time on Stack Overflow trying to find out how to do this.

References:

  1. "Updating ~/.lein/profiles.clj to {:repl {:dependencies [^:displace [org.clojure/clojure "1.9.0"]]}} does not seem to work. – Petrus Theron Jan 10 2018 at 9:05" How do you change Clojure version in Leiningen and LightTable?

  2. "I asked technomancy on IRC just now. He said: "REPL's outside projects are hard coded to lein's version of clojure". – David J. Feb 24 '14 at 19:52" How to change Clojure or Lein's Clojure default version?

  3. "this ^:displace trick will not work with tools.nrepl or clojure-complete." https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md

  4. How to upgrade nrepl version of leiningen?

sailco12
  • 87
  • 5
  • This doesn't read like a question to me ... if you want to suggest a change to Leiningen you could do that on the Leiningen issue tracker, no? – glts Jan 28 '18 at 13:26
  • @glts Good idea. I put it an issue called "Friendlier Leiningen watches for issues and warns" at https://github.com/technomancy/leiningen/issues/2394 Do you think I should close this question now? – sailco12 Jan 29 '18 at 17:55

1 Answers1

1

I think you may try to declare different profiles in your project.clj where each of them has its own Clojure version. For example:

  :profiles
  {;; :default [:base :system :user :provided :dev]
   :server-jvm {:jvm-opts ^:replace ["-server"]}
   :1.5  {:dependencies [[org.clojure/clojure "1.5.1"]]}
   :1.6  {:dependencies [[org.clojure/clojure "1.6.0"]]}
   :1.7  {:dependencies [[org.clojure/clojure "1.7.0"]]}
   :1.8  {:dependencies [[org.clojure/clojure "1.8.0"]]}
   :1.9  {:dependencies [[org.clojure/clojure "1.9.0"]]}}

Now that, when running any Lein command, specify a profile as follows:

lein with-profile 1.7 repl

The REPL session of Clojure 1.7 should start.

I grabbed that fragment from carmine sources. The official Lein profiles manual also has the same example.

Ivan Grishaev
  • 1,583
  • 10
  • 15
  • Ivan, Thanks, I'm glad to know this, but I don't think Leiningen looks at any "project.clj" file unless the command is issued from the root directory (or below) of such a file. The question discusses the "(lein repl)" command iissued outside of a project directory. – sailco12 Jan 29 '18 at 17:59