clojureversionversioningleiningendeps-edn

What is a common convention for storing a project version number in a Clojure project?


Our team is working with Clojure projects that use deps.edn

We are used to NPM projects where we store the version number in the package.json file. It looks like Leiningen users may have stored the version number in a project.clj file before. Is there a community-wide convention for versioning Clojure projects? I have seen that people and official docs mention using Git tags but wondering if there is some popular way that developers using deps.edn store the version number in a file.

Thank you!


Solution

  • I have only used Leiningen to publish JAR files so far. In this case, the version string is at the top of the file like

    (defproject tupelo/demo "0.1.0-SNAPSHOT"
    

    and it is most easily maintained by just editing project.clj.

    Just last month, the final version of tools.build was released, which is the "official" way of publishing JAR files using the Deps/CLI system. I haven't had a chance to play with it yet but the example in the guide shows how to include the version string when building a JAR file. The example even uses an automation technique based on counting commits in git.

    (ns build
      (:require [clojure.tools.build.api :as b]))
    
    (def lib 'my/lib1)
    (def version (format "1.2.%s" (b/git-count-revs nil)))
    (def class-dir "target/classes")
    (def basis (b/create-basis {:project "deps.edn"}))
    (def jar-file (format "target/%s-%s.jar" (name lib) version))
    
    (defn clean [_]
      (b/delete {:path "target"}))
    
    (defn jar [_]
      (b/write-pom {:class-dir class-dir
                    :lib lib
                    :version version
                    :basis basis
                    :src-dirs ["src"]})
      (b/copy-dir {:src-dirs ["src" "resources"]
                   :target-dir class-dir})
      (b/jar {:class-dir class-dir
              :jar-file jar-file}))