(ns build (:require [clojure.tools.build.api :as b])) (defn make-class-dir [target] (format "%s/classes" target)) (def basis (b/create-basis {:project "deps.edn"})) (defonce timestamp (.format (java.time.LocalDateTime/now) java.time.format.DateTimeFormatter/BASIC_ISO_DATE)) (defonce default-target "./target") (defonce default-srcs ["src"]) (defn make-jar-filename [target project version] (format "%s/%s-%s.jar" target (name project) version)) (defn make-uber-filename [target project version] (format "%s/%s-%s-standalone.jar" target (name project) version)) (defn clean [{:keys [target] :or {target default-target} :as params}] (println (format "removing build target folder \"%s\"" target)) (b/delete {:path target}) params) (defn lib-jar [{:keys [project version target srcs] :or {version timestamp target default-target srcs default-srcs} :as params}] (let [project-sym (symbol project) target-jar (make-jar-filename target project version) class-dir (make-class-dir target)] (clean params) (b/copy-dir {:src-dirs srcs}) (b/compile-clj {:basis basis :src-dirs srcs :class-dir class-dir}) (b/write-pom {:class-dir class-dir :lib project-sym :version version :basis basis :src-dirs srcs}) (b/jar {:class-dir class-dir :jar-file target-jar}) (println (format "jar file created at: %s" target-jar))) params) (defn lib-uberjar [{:keys [project version target srcs] :or {version timestamp target default-target srcs default-srcs} :as params}] (let [project-sym (symbol project) target-uber (jar-filename target project version) class-dir (make-class-dir target)] (clean params) (b/copy-dir {:src-dirs srcs :target-dir class-dir}) (b/compile-clj {:basis basis :src-dirs srcs :class-dir class-dir}) (b/uber {:class-dir class-dir :uber-file target-uber :basis basis}) (println (format "uberjar file created at: %s" target-uber))) params)