clojureconfigleiningenedn

yogthos/config picking up my env in CIDER, but not when run in lein with-profile


working on this simple demo project, I've started with my own "config management". Basically, slurp the .edn file into a string, and then edn/read-string it into a map. It worked fine, but then I got to the integration tests, and that calls for different config files.. so I searched and found this yogthos/config thing, which seemed to be made exactly for this.

Quickly tested, it seems to be doing what I want. Evaluating in my Emacs attached to a REPL server, I can evaluate the config value of interest.

(println "HERE IT IS!!: " (:kafka-broker env))
(def p (producer (:kafka-broker env)))

When I compile the file, it prints the message with the config value. However, when I run lein with-profile dev uberjar, it dies right there with an exception,

Caused by: java.lang.IllegalArgumentException: requirement failed: Missing required property 'metadata.broker.list'
    at scala.Predef$.require(Predef.scala:233)

, and my println, which was added for this purpose, confirms the suspicion:

HERE IT IS!!:  nil

But.. but... I did give it with-profile dev..?

lein with-profile dev pprint output looks right, but I probably don't know what to look for:

...
 :resource-paths
 ("/Users/akarpov/repos/coras/config/dev"
  "/Users/akarpov/repos/coras/resources"),
...

lastly, this is from my project.clj:

...
  :profiles {:prod {:resource-paths ["config/prod"]}
             :dev  {:resource-paths ["config/dev"]}
             :uberjar {:aot :all}}
...

Solution

  • ok I think I found the answer (and it had to do with my lack of knowledge about how project.clj really works)

    basically, as was pointed out in the comment above, running uberjar task indeed implicitly runs it in an built-in profile of some sort.

    so I thought ok, let's run 'repl' task with the dev profile. Then I got an error about a missing nrepl.server; which is implicitly a part of some built-in default profile (lein repl is running fine). After adding that as an explicit thing, it seems to work:

      :profiles {:prod {:resource-paths ["config/prod"]
                        :plugins [[cider/cider-nrepl "0.16.0"]]}
                 :dev  {:resource-paths ["config/dev"]
                        :plugins [[cider/cider-nrepl "0.16.0"]]}
                 :uberjar {:aot :all}}
    

    after getting over that, the next problem was to make sure yberjar task doesn't override my prod profile, so need to insist on that value to be kept:

    :profiles {:prod {:resource-paths ^:replace ["config/prod"]
                        :plugins [[cider/cider-nrepl "0.16.0"]]}