Embed version string from leiningen project in application

前端 未结 5 1030
执念已碎
执念已碎 2020-12-16 16:44

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,

5条回答
  •  暖寄归人
    2020-12-16 17:33

    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 under

    META-INF/maven/com.example/my-project/pom.properties
    

    which you can read into a java.util.Properties and get out a "version" key.

    (ns com.example.version
      (:require [clojure.java.io :as io])
      (:import (java.util Properties)))
    
    (defn read-project-version [groupid artifact]
      (-> (doto (Properties.)
            (.load (-> "META-INF/maven/%s/%s/pom.properties"
                     (format groupid artifact)
                     (io/resource)
                     (io/reader))))
        (.get "version")))
    

提交回复
热议问题