How do you determine the current leiningen profiles from a running repl?
Asked Answered
S

2

9

The current set of active profiles is not clear when your IDE has started the REPL for you. In this case, can you query Leiningen somehow to figure out what they may be?

Starkey answered 16/6, 2016 at 20:46 Comment(1)
Don't know a general answer, but you could always make a temporary project.clj file with only 1 profile in it. Be sure to disable ~/.lein/profiles.clj also.Sheets
V
1

Usually I define various profiles on my project.clj pointing to different config files for each one of them like

  :profiles {:release {:resource-paths ["config/release"]
                          :source-paths ["src"]
                          }
             :test {:resource-paths ["config/test"]
                       :source-paths ["src" "test"]
                       }
             :dev {:resource-paths ["config/dev"]
                   :source-paths ["src" "dev"]}}

So, for every folder inside "config" has a config.edn in it containing the needed info for every profile that I have, you could add a :profile keyword in each config.edn with a different value for each one to show which profile is active at that moment. I use yogthos config to load the config files.

Besides that, I really don't the idea of the IDE controlling the nrepl, normally it kills the repl when the IDE is closed and they can be very restrictive on the options you pass to lein. I prefer to start the repl in a different terminal than my editor with lein with-profile dev repl and then connecting that nrepl session on my editor, that way you'll be sure of which profile you are using.

Vachon answered 24/2, 2020 at 22:29 Comment(0)
P
1

To my knowledge there is no way to see which profiles are loaded as part of a running REPL. Just like any program wouldn't know which terminal window it was started from. That said, profiles and how they work is documented.

Also it isn't always enough to just know which are "active". Sometimes it is also relevant to know in which order.

To play around with this add the following to your project.clj:

  :profiles {
             :dev {:injections [(prn "including dev profile")]}
             :test {:injections [(prn "including test profile")]}
             :repl {:injections [(prn "including repl profile")]}
             :my-profile {:injections [(prn "including my-profile profile")]}

Now run the following and look for the output "including ...:

lein repl
lein test
lein with-profile my-profile test
lein with-profile +my-profile test

Note that :injections is not executed in jars or uberjars (lein jar and lein uberjar). Which is why I excluded this from the above playground.

Paugh answered 11/3, 2020 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.