technomancy / leiningen

Moved to Codeberg; this is a convenience mirror
https://codeberg.org/leiningen/leiningen
Other
7.29k stars 1.61k forks source link

Lein fails to correctly activate :dev profile #1666

Closed Gastove closed 9 years ago

Gastove commented 10 years ago

Something is causing lein to incorrectly merge my :dev profile from my project.clj. This is the squirreliest thing I've encountered yet. Observe:

I have the following profile configs set:

;;; My global .lein/profiles.clj
{:user
 {:plugins [[cider/cider-nrepl "0.8.0-SNAPSHOT"]
            [lein-plz "0.2.1"]
            [lein-pprint "1.1.1"]]
  :dependencies [[alembic "0.2.1"]
                 [slamhound "1.5.5"]]
  :aliases {"slamhound" ["run" "-m" "slam.hound"]}}}

;;; From my project.clj
:profiles {:production {:env {:production true
                                :timbre-log-level :info}}
             :dev {:env {:production false
                         :timbre-log-level :debug
                         :port 5000}
                   :dependencies [[cheshire "5.3.1"]         ;; <-- This is here for demonstration.
                                  [ring-mock "0.1.5"]]}}

Now, in a REPL session launched from my project root:

nREPL server started on port 53600 on host 127.0.0.1 - nrepl://127.0.0.1:53600
REPL-y 0.3.2, nREPL 0.2.3
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609
    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=> (require '[environ.core :refer [env]])
nil
user=> (env :port)     ;; <-- Should be 5000
nil
user=> (require '[cheshire.core :as json])
nil
user=> (json/generate-string {:a "cat"})
"{\"a\":\"cat\"}"
user=> (require '[ring.mock.request])

FileNotFoundException Could not locate ring/mock/request__init.class or ring/mock/request.clj on classpath:   clojure.lang.RT.load (RT.java:443)

I get this result even if I explicitly activate the dev profile (i.e. lein with-profile +dev repl)

If I move the dep declaration for ring.mock out in to the main project deps list, it loads perfectly. I have access to a second computer; on that computer, the :dev profile of the project loads flawlessly -- ports get set, all dependencies are available. However, as nearly as I can tell, both machines are set up identically. Both machines have the same .lein/profiles.clj. Both are running:

$ lein --version
Leiningen 2.4.3 on Java 1.6.0_65 Java HotSpot(TM) 64-Bit Server VM

I can't find any obvious environment variable differences. In fact, I am completely at a loss. I'm not even entirely sure what information to post here to help track this down -- please just let me know if there's any other info I can provide. For now, I'll mention I'm on OsX 10.9, and that the most current version of my project.clj is here.

Thoughts?

technomancy commented 10 years ago

I can't reproduce this problem with the project.clj and profiles.clj listed above. Can anyone else trigger it?

hypirion commented 10 years ago

I tried on lein 2.5.0 and wasn't able to reproduce. I added the following dependencies and plugins in project.clj to get environ up and running:

:dependencies [[org.clojure/clojure "1.6.0"]
                 [environ "1.0.0"]]
  :plugins [[lein-environ "1.0.0"]]
technomancy commented 9 years ago

Sounds like this is fixed in 2.5.0 then.

virmundi commented 9 years ago

I have the same problem. I too am on OS X.

Exception in thread "main" java.io.FileNotFoundException: Could not locate ring/mock/request__init.class or ring/mock/request.clj on classpath: , compiling:(deusdatsolutions/handler_test.clj:1:1)

I'm on lein 2.5.1.

(defproject deusdatsolutions "0.1.0"
  :description "Company site, but in Clojure."
  :url "http://www.deusdatsolutions.com"
  :min-lein-version "2.0.0"
  :source-paths ["src/clj"]
  :main deusdatsolutions.handler

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [compojure "1.3.1"]
                 [ring/ring-defaults "0.1.2"]
                 [hiccup "1.0.5"]
                 [environ "1.0.0"]
                 [com.draines/postal "1.11.3"]
                 [http-kit "2.0.0"]
                 [org.clojure/tools.logging "0.3.1"]]

  :plugins [[lein-ring "0.8.13"]
            [lein-cljsbuild "1.0.3"]
            [lein-pdo "0.1.1"]
            [lein-environ "1.0.0"]]

  :ring {:handler deusdatsolutions.handler/app}
  :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                                  [ring-mock "0.2.0"]
                                  [midje "1.6.3"]]
                   :env {:dev true, 
                         :production false}}
             :uberjar {:aot :all}})
samsondav commented 9 years ago

Same problem for me on OS X.

Leiningen 2.5.1 on Java 1.8.0_25 Java HotSpot(TM) 64-Bit Server VM

The problem is only triggered occasionally and when I change (and save) a file while the running lein ring server. After restarting the server it always works fine.

clojure.lang.Compiler$CompilerException: java.io.FileNotFoundException: Could not locate ring/mock/request__init.class or ring/mock/request.clj on classpath: , compiling:(smio_fb/test/handler.clj:1:1)

My project.clj

(defproject smio-fb "0.1.0-SNAPSHOT"

  :description "FIXME: write description"
  :url "http://example.com/FIXME"

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [ring-server "0.4.0"]
                 [selmer "0.8.2"]
                 [com.taoensso/timbre "3.4.0"]
                 [com.taoensso/tower "3.0.2"]
                 [markdown-clj "0.9.65"]
                 [environ "1.0.0"]
                 [im.chit/cronj "1.4.3"]
                 [compojure "1.3.3"]
                 [ring/ring-defaults "0.1.4"]
                 [ring/ring-session-timeout "0.1.0"]
                 [ring-middleware-format "0.5.0"]
                 [noir-exception "0.2.5"]
                 [bouncer "0.3.2" :exclusions [clj-time]]
                 [prone "0.8.1"]
                 [org.clojure/tools.nrepl "0.2.10"]
                 [ragtime "0.3.8"]
                 [yesql "0.5.0-rc3" :exclusions [instaparse]] ; it's included in compojure
                 [org.postgresql/postgresql "9.4-1201-jdbc41"]
                 [org.clojure/data.json "0.2.6"]
                 [ring-cors "0.1.7"]]

  :min-lein-version "2.0.0"
  :uberjar-name "smio-fb.jar"
  :jvm-opts ["-server"]

;;enable to start the nREPL server when the application launches
;:env {:repl-port 7001}

  :main smio-fb.core

  :plugins [[lein-ring "0.9.1"]
            [lein-environ "1.0.0"]
            [lein-ancient "0.6.5"]
            [ragtime/ragtime.lein "0.3.8"]]

  :ring {:handler smio-fb.handler/app
         :port 3001 ;; avoid conflict with rails
         :init    smio-fb.handler/init
         :destroy smio-fb.handler/destroy
         :uberwar-name "smio-fb-rest.war"}

  :ragtime
  {:migrations ragtime.sql.files/migrations
   :database
   "jdbc:postgresql://localhost/smio_fb?user=db_user_name_here&password=db_user_password_here"}

  :profiles
  {:uberjar {:omit-source true
             :env {:production true}

             :aot :all}
   :dev {:dependencies [[ring-mock "0.1.5"]
                        [ring/ring-devel "1.3.2"]
                        [pjstadig/humane-test-output "0.7.0"]
                        ]
         :source-paths ["env/dev/clj"]
         :jvm-opts "-XX:-OmitStackTraceInFastThrow"

         :repl-options {:init-ns smio-fb.repl}
         :injections [(require 'pjstadig.humane-test-output)
                      (pjstadig.humane-test-output/activate!)]
         :env {:dev true}}})

Let me know if you need any more information to help reproduce.

devn commented 9 years ago

I'm in the same boat.

asultanpur commented 9 years ago

It happens every time I change a file, exactly once. I have a profiles.cljin the project directory which defines the environment for the dev profile. It doesn't show the error when I remove the dev profile settings from profiles.clj.

nberger commented 9 years ago

I have a profiles.clj in the project directory which defines the environment for the dev profile. It doesn't show the error when I remove the dev profile settings from profiles.clj.

When you define a :dev profile in both project.clj and profiles.clj, they won't be merged: the one in project.clj will be ignored, only the one in profiles.clj will be taken into account. That's exactly why the error doesn't happen if you remove the dev profile in profiles.clj.

This is a very frequent issue when using environ: The README recommends to specify the dev env variables under a dev profile in profiles.clj but it doesn't explain it will overwrite any dev profile in project.clj. It's a known issue (weavejester/environ#15), there are workarounds explained in that issue, but the README is still misleading.

samsondav commented 9 years ago

@nberger Great answer, thank you.