Is it possible to grab the project information within the clojure repl?
For example, if there was a project defined:
(defproject blahproject "0.1.2" ....)
When running a repl in the project directory, is there a function like this?
> (project-version)
;=> 0.1.2
As vemv said, Leiningen project files are just Clojure data. So, it's easy to access your project as an ordinary
hash-map
:If you need this variable only in your
repl
, you can add it torepl-options
to yourproject.clj
:Now, you have
project
variable in yourrepl
. So, to access the version of your project you can simply type(:version project)
.Of course, you can simply use native Leiningen code to parse you project file:
But, if you need only the version of your project and nothing more, then it's best to use Ankur's solution.
I use environ (https://github.com/weavejester/environ) which sucks in settings from a number of sources, including system properties. The project version appears as
:<project-name>-version
:While you can parse
project.clj
yourself, this may be annoying. It's also a lot of work. Instead, you can just do:Leiningen project files are just Clojure data :)
(-> "/path/to/project.clj" slurp read-string (nth 2))
Add the below code to the end of project.clj:
Now you will have a var called
project-version
in the initial namespace for the repl.As described in this discussion.