Reading app version from build.boot file in application

Hello,

We want to add cache bursting of some assets/urls of our app based on the app version. So we need to be able to read the version from the buid.boot file itself in our app.

No idea how to do it, reading the docs of boot doesn’t help me so far… Any pointer appreciated !

Not sure how to read it from boot but you could always generate a version file in resources and read that file.

Or if you can set the manifest Implementation-Version during build you can read the jar version via Java. That also requires :aot for the Clojure namespace.

If you use the pom task to include a pom.xml in the artifact, you can read it from there.

E.g.:

user> (require '[clojure.java.io :as io])
nil
user> (require '[clojure.data.xml :refer :all])
nil
user> (def xml-str (slurp (io/resource "META-INF/maven/my/project/pom.xml")))
#'user/xml-str
user> (->> xml-str parse-str :content (filter #(= :version (:tag %))) first :content first)
"0.1.0-SNAPSHOT"

Thanks guys, we went this way finally: create a dumb version.txt file in resources and read it both from build.boot ((def version (slurp "version.txt")) and from our code. Simple enough.

Beware when using anything from the classpath with such a generic name. Should any library include a version.txt it will be loaded before yours thus giving you the “wrong” version.

Always ensure to namespace everything on the classpath.

3 Likes

Good advice thank you.