这对于决定是否发布 SNAPSHOT 版本非常有用。
以下是如果您想将其用于当前项目的有效实现:
(ns build
(:require [clojure.string :as str]
[clojure.tools.build.api :as b]
[clojure.tools.build.api.specs :as specs]))
(defn git-branch
"Shells out to git and returns the current branch
git branch --show-current
Options:
:dir - dir to invoke this command from, by default current directory"
[{:keys [dir] :or {dir "."} :as params}]
(@#'b/assert-specs "git-branch" params :dir ::specs/path)
(-> {:command-args ["git" "branch" "--show-current"]
:dir (.getPath (b/resolve-path dir))
:out :capture}
b/process
:out
str/trim))
(def lib 'my-group/my-lib)
(def version
(if (= "master" (git-branch nil))
(format "1.0.%s" (b/git-count-revs nil))
(format "1.0.%s-SNAPSHOT" (b/git-count-revs nil))))