Fork me on GitHub
#cider
<
2022-02-07
>
Zach Mitchell01:02:34

I'm having an issue loading my dependencies. When I user CIDER to connect to a REPL without my :dev alias everything seems to work fine with the exception of a warning when evaluating server.clj (source below):

Warning: environ value /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home for key :java-home has been overwritten with /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre
This appears to be coming from environ, but I don't know why. When I activate my :dev alias my dependencies are no longer found on the classpath:
Syntax error (FileNotFoundException) compiling at (src/zmitchell/cheffy/server.clj:1:1).
Could not locate reitit/ring__init.class, reitit/ring.clj or reitit/ring.cljc on classpath.
This is the command that CIDER is using to jack-in:
/usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0-beta3"} refactor-nrepl/refactor-nrepl {:mvn/version "3.0.0-alpha13"} cider/cider-nrepl {:mvn/version "0.27.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}}' -M:dev:cider/nrepl
This is what my deps.edn file looks like:
{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        ring/ring {:mvn/version "1.8.1"}
        integrant/integrant {:mvn/version "0.8.0"}
        environ/environ {:mvn/version "1.2.0"}
        metosin/reitit {:mvn/version "0.5.2"}
        seancorfield/next.jdbc {:mvn/version "1.0.462"}
        org.postgresql/postgresql {:mvn/version "42.2.14"}
        clj-http/clj-http {:mvn/version "3.10.0"}
        ovotech/ring-jwt {:mvn/version "1.2.5"}}
 :aliases
 {:run-m {:main-opts ["-m" "zmitchell.cheffy.server"]}
  :web {:main-opts ["-m" "zmitchell.cheffy.server"]}
  :run-x {:ns-default zmitchell.cheffy
          :exec-fn greet
          :exec-args {:name "Clojure"}}
  :build {:deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.4.0" :git/sha "54e39ae"}}
          :ns-default build}
  :dev {:extra-paths ["dev"]
        :deps {integrant/repl {:mvn/version "0.3.1"}
               ring/ring-mock {:mvn/version "0.4.0"}}}
  :test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
                      io.github.cognitect-labs/test-runner
                      {:git/tag "v0.5.0" :git/sha "48c3c67"}}}}}
This is what server.clj looks like:
(ns zmitchell.cheffy.server
  (:require [reitit.ring :as ring]
            [ring.adapter.jetty :as jetty]
            [integrant.core :as ig]
            [environ.core :refer [env]]))

(def app
  (ring/ring-handler
   (ring/router
    ["/"
     {:get {:handler (fn [req] {:status 200 :body "Hello, World!"})}}])))

(defmethod ig/init-key :server/jetty
  [_ {:keys [handler port]}]
  (jetty/run-jetty handler {:port port :join? false}))

(defmethod ig/prep-key :server/jetty
  [_ config]
  (merge config {:port (Integer/parseInt (env :port))}))

(defmethod ig/halt-key! :server/jetty
  [_ server]
  (.stop server))

(defmethod ig/init-key :cheffy/app
  [_ config]
  (app config))

(defmethod ig/init-key :db/postgres
  [_ config]
  (:jdbc-url config))

(defn -main
  [config-file]
  (let [config (-> config-file
                   slurp
                   ig/read-string)]
    (-> config
        ig/prep
        ig/init)))

dpsutton02:02:26

You have :dev {:deps {}} but :test {:extra-deps {}}. Maybe try switching to use extra-deps?

dpsutton02:02:39

I think :deps is the same as :replace-deps

dpsutton03:02:42

also, when i run into issues I would just remove CIDER and see if the issue persisted. You should have seen this behavior from just clj -A:dev i think. The repl also always prints up how it starts the clj and repl and how it starts the cljs repl (when appropriate) so it should remove any semblance of magic. You can try out its commands in a terminal to ensure you get all error messages and then slowly start pulling out tooling.

👍 1
Zach Mitchell04:02:04

This fixed it, thank you!

Zach Mitchell20:02:50

I'm having trouble getting my user.clj picked up when I load a file in my editor. When I start a REPL with clj -A:dev:test the functions in user.clj are available. However, when I start a REPL from Emacs using the jack-in command below, the functions are no longer available:

/usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0-beta3"} refactor-nrepl/refactor-nrepl {:mvn/version "3.0.0-alpha13"} cider/cider-nrepl {:mvn/version "0.27.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}}' -M:dev:test:cider/nrepl
When I say that the functions are no longer available, I mean that when I'm inside a file, say src/zmitchell/cheffy/server.clj and try to evaluate the (go) inside (comment (go)) I get an error saying that the symbol go could not be resolved. My user.clj is at dev/user.clj and I include dev in the :extra-paths of the :dev alias. I've attached some relevant files for troubleshooting.

vemv22:02:07

user.clj does not define globally-referred functions. The user ns is (almost) like any other one, so once you are in the cider REPL, you should make sure that your current ns is user, not server

vemv22:02:57

Or if you want the repl to stay in namespaces other than user , use fully-qualified function names (via key bindings, or maybe yasnippets)

vemv22:02:49

Lastly, I think cider/nrepl is not an alias that CIDER (publicly) defines? I'd recommend using a different name that does not possibly clash with actual cider internals.

Zach Mitchell23:02:20

Actually the current namespace is user (according to the REPL prompt). The cider/nrepl alias is part of the jack-in command that CIDER generates, that's not something I've set on my own.

👍 1
Zach Mitchell23:02:16

If I'm editing server.clj I can call the functions via user/go, so the functions are loaded. I just can't access without a namespace like I thought I could.

vemv23:02:05

Indeed, user.clj does not define globally-referred functions

vemv23:02:59

btw, an idiomatic approach for a "Reloaded" workflow would be tweaking cider-ns-refresh-after-fn and cider-ns-refresh-before-fn , you can find some recent results on this Slack

Zach Mitchell23:02:51

I'll take a look, thanks!

cider 1
practicalli-johnny10:02:47

When calling (go) or (reset) I tend to do that from the user buffer, or have the REPL buffer open and in the user namespace - especially if logs are sent to the REPL

domingues21:02:11

How can i use cider REPL, on emacs ,to evaluate clojure functions on a .clj file that isn't associated to a lein project .

domingues18:02:23

Cool ! Thanks !

cider 1