leiningen

apt 2022-07-25T14:38:38.883469Z

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.

apt 2022-07-26T13:32:18.552429Z

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

vemv 2022-07-26T13:35:02.643349Z

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

apt 2022-07-26T13:37:27.596079Z

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.

vemv 2022-07-26T13:41:51.332679Z

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

apt 2022-07-26T13:42:47.700789Z

Ah, okay, makes sense 👍

apt 2022-07-26T13:43:07.472669Z

Thanks for the suggestion gratitude

🍻 1
vemv 2022-07-25T15:13:39.371279Z

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)))
                  `foo)])
Then you can (read-string (System/getProperty "lein-project")) in your project repl

apt 2022-07-25T17:12:14.491439Z

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.

vemv 2022-07-26T06:47:07.496939Z

You can extract the same middleware to a Lein plugin