sailco12
sailco12

Reputation: 87

How to change Lein's Clojure default version outside of a project directory?

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?

Upvotes: 3

Views: 1363

Answers (1)

Ivan Grishaev
Ivan Grishaev

Reputation: 1681

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.

Upvotes: 1

Related Questions