Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run lein repl without explicit dependency on tools.nrepl #27

Open
atroche opened this issue Apr 30, 2018 · 6 comments
Open

Can't run lein repl without explicit dependency on tools.nrepl #27

atroche opened this issue Apr 30, 2018 · 6 comments

Comments

@atroche
Copy link
Contributor

atroche commented Apr 30, 2018

project.clj:

(defproject blah "0.1.0-SNAPSHOT"
  :plugins [[lein-tools-deps "0.3.0-SNAPSHOT"]]
  :tools/deps [:system :home :project])

deps.edn:

{:deps {}}
~/c/blah> lein repl
Warning: no nREPL dependency detected.
Be sure to include org.clojure/tools.nrepl in :dependencies of your profile.
Error loading clojure.tools.nrepl.server: Could not locate clojure/tools/nrepl/server__init.class or clojure/tools/nrepl/server.clj on classpath.
Error loading complete.core: Could not locate complete/core__init.class or complete/core.clj on classpath.
Exception in thread "main" java.lang.ClassNotFoundException: clojure.tools.nrepl.server, compiling:(/private/var/folders/25/z_59070d5135pdfd4y1c1td00000gn/T/form-init7534147402379510545.clj:1:1093)

Changing deps.edn to the following fixes it:

{:deps {org.clojure/tools.nrepl {:mvn/version "0.2.12"}}}
@atroche
Copy link
Contributor Author

atroche commented Apr 30, 2018

And complete.core is https://clojars.org/clojure-complete, just by the by.

@RickMoynihan
Copy link
Owner

Currently this is expected, as I think we replace the whole :dependencies vector. The advantage of this approach is that the semantics are clear and you should get the same as with tools.deps. The disadvantage is that you don't get any dependencies from leiningen profiles etc; which means tasks such as repl that merge profiles won't have their dependencies merged.

Doing something better would be good, but I don't know how we can make it do the right thing for the current task. I'm don't think always merging the repl profile merged is the right thing to do as other tasks work this way too).

I'm not 100% sure yet, but I think if we were to do this we'd need to investigate replacing this line:

With something more subtle, I suspect we probably want to merge the :dependencies from tools.deps into the appropriate profile e.g. :base or whichever it is; and rely on leiningen doing the rest for us with merge-profiles etc.

I'm not currently clear enough on the actual execution order of middleware's and profile merging to be sure what to do yet. We should investigate.

@mfikes
Copy link
Contributor

mfikes commented May 1, 2018

Yeah, perhaps if the lein-tools-deps config ends up being a map, you could opt into or out of getting these https://github.com/technomancy/leiningen/blob/3fd92945ba25837afb5f9c14cafdafb8e70a493e/leiningen-core/src/leiningen/core/project.clj#L543-L546

@mfikes
Copy link
Contributor

mfikes commented May 1, 2018

For those encountering this ticket, to have the default behavior, you'd start with a deps.edn that looks like this:

{:deps {clojure-complete {:mvn/version "0.2.4" :exclusions [[org.clojure/clojure]]}
        org.clojure/tools.nrepl {:mvn/version "0.2.12" :exclusions [[org.clojure/clojure]]}}}

@RickMoynihan
Copy link
Owner

Yeah, perhaps if the lein-tools-deps config ends up being a map, you could opt into or out of getting these https://github.com/technomancy/leiningen/blob/3fd92945ba25837afb5f9c14cafdafb8e70a493e/leiningen-core/src/leiningen/core/project.clj#L543-L546

Yes, but I think if you want to do it properly (if that's even possible) we'd also need to ensure profiles for the running task are merged properly e.g. the lein repl task also specifies this profile:

https://github.com/technomancy/leiningen/blob/3fd92945ba25837afb5f9c14cafdafb8e70a493e/src/leiningen/repl.clj#L199-L203

Clearly we can't maintain profiles for each and every possible leiningen task, so I'd like to find a better way. It feels like the best thing is probably to ensure that we only replace :dependencies for the profile within which :tools/deps is defined, so that it is properly scoped and that leiningen can then perform profile merging.

Naturally this assumes that middlewares are applied before profiles are merged... I suspect that's true, but I haven't checked yet.

@delitescere
Copy link

Maybe, at least for determining dependencies, it'll be about mapping a lein profile to a list of tools.deps aliases?

Have a look at Juxt's "Edge" project. This is a pure clj / tools.deps project that includes access to a REPL. The REPL is quite loaded with features with all the dependencies they have, but I've removed the extraneous stuff for clarity.

a bin/repl script that does this:

clojure -A:dev/nrepl

a deps.edn with the following aliases:

:aliases
 {:dev/nrepl {:jvm-opts ["-Dedge.load_nrepl=true"]}
  :extra-paths ["aliases/nrepl"]
  :extra-deps
  {org.clojure/tools.nrepl {:mvn/version "0.2.12"}}}}

a dev/user.clj containing:

(ns user
  (:require
   [clojure.tools.namespace.repl :refer :all]))

(when (System/getProperty "edge.load_nrepl")
  (require 'nrepl))

and a aliases/nrepl.clj containing:

(ns ^{:clojure.tools.namespace.repl/load false} nrepl
  (:require
   [clojure.tools.nrepl.server :as nrepl.server]))

(defn start-nrepl
  [opts]
  (let [server
        (nrepl.server/start-server
          :port (:port opts))]
    (spit ".nrepl-port" (:port server))
    server))

(def server (start-nrepl {:port 5600}))

This works. What can go in a project.clj, is replace the bin/repl with the task definition listing the aliases from deps.edn to use and include extra paths for, and perhaps replace the dev/user.clj with an unconditional require of nrepl (from aliases/nrepl.clj) to run the REPL (although I use this dev/user.clj / dev/dev.clj approach even with lein).

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants