I want to be able to query or embed the version string set by the leiningen project and display that value to user. Uses include displaying the version string from the CLI, or as a header in a ring application. Is this possible?
相关问题
- Better Sequence Duplicate Remover
- Installation of Leiningen 2.X in Mac OS X
- Questions about Lists and other stuff in Clojure
- How do I add CORS to a compojure-api app?
- How do I use Clojure in Android Studio using Gracl
相关文章
- Factor Clojure code setting many different fields
- Does learning one Lisp help in learning the other?
- Better way to nest if-let in clojure
- Idiomatic approach for structuring Clojure source
- Is a “transparent” macrolet possible?
- Detect operating system in Clojure
- Using quote in Clojure
- Enums and Clojure
I like technomancy's answer, but I had to go look up how to "read
pom.properties
". It turns out that for the maven artifact com.example/my-project, there is a file on the classpath underwhich you can read into a java.util.Properties and get out a "version" key.
Someone has written a nice library for handling this: https://github.com/trptcolin/versioneer
It works for lein projects, both running in lein and from an uberjar. Use it like the following (taken from the Github page):
If you're running inside Leiningen using
lein run
or the like, it's available as a system property:(System/getProperty "myproject.version")
. If you're producing a jar you need to readpom.properties
.if you build a jar file you can extract the current version from the jar file.
otherwise if you are not doing AOT then you can
read
the project.clj file (because it's a map) and then extract the version.I certainty hope there is a more elegant solution short of writing a leiningen plugin for this (unless someone else wants to write this, hint hint..)
Here is how I read my project name and version, note that the
project.clj
file is read during compilation and jar file simply contains the string:so for
(defproject abc "1.2.3" ...
, when you run-main
it will print: