Fork me on GitHub

Hi folks. I’d like to get the value of some alias at runtime.

(apply hash-map (drop 3 (let [project-path "project.clj"]
                                  (when (.exists (io/as-file project-path))
                                    (read-string (slurp project-path))))))
I’m using this. The whole file is list: it’s first element is defproject, the second is the name of the project, and so on. I’m wondering if this drop 3 is reliable or if there’s a better way of doing that.


I'd suggest instead sth like

(defproject p "0"
  :middleware [~(do
                  (defn foo [project]
                    (-> project
                        (update :jvm-opts conj (str "-Dlein-project=" (pr-str project)))
                        (update :jvm-opts vec)))
Then you can (read-string (System/getProperty "lein-project")) in your project repl


Interesting! The thing is that the tool will be injected on many projects as they are, with no modifications. So unfortunately I can’t use this custom logic. In any case, I didn’t know that was possible, thanks.


You can extract the same middleware to a Lein plugin


And inject the plugin with lein update-in, right? Yeah, sounds feasible.


You can simply add the plugin to ~/.lein/profiles.clj


I think I forgot to explain the full context here. The code I proposed would reside in a library that is injected in many Clojure services in a pipeline. It extracts information from tests, so whenever one commits something to a service, that lib runs in the service in a pipeline (with lein update-in, which appends the lib as a dependency). That’s why I have little control over the service code.


Yeah update-in can inject plugins :) Writing to the :user profile in ~/.lein/profiles.clj should work in CI as well


Ah, okay, makes sense :thumbsup:


Thanks for the suggestion gratitude

🍻 1