-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.clj
90 lines (65 loc) · 2.24 KB
/
build.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(ns build
(:import
[java.time LocalDateTime]
[java.time.format DateTimeFormatter])
(:require
[clojure.java.io :as io]
[clojure.tools.build.api :as b]
))
(def APP_NAME (System/getenv "APP_NAME"))
(def VER_MAJOR (System/getenv "VER_MAJOR"))
(def VER_MINOR (System/getenv "VER_MINOR"))
(def MAIN_CLASS (System/getenv "MAIN_CLASS"))
(def JAVA_SRC "./java")
(def RESOURCES "./resourses")
(def TARGET "./target")
(def CLASS_DIR "./target/classes")
(def TARGET_RESOURCES "./target/resources")
(def BUILD_INFO "build-info.edn")
(def JAR_NAME (str APP_NAME ".jar"))
(defn iso-now ^String []
(.format (LocalDateTime/now) DateTimeFormatter/ISO_LOCAL_DATE_TIME))
(defn clean [_]
(b/delete {:path TARGET}))
(defn version [_]
(format "%s.%s.%s" VER_MAJOR VER_MINOR (b/git-count-revs nil)))
(defn build-info [_]
{:appname APP_NAME
:version (version nil)
:branch (b/git-process {:git-args "branch --show-current"})
:commit (b/git-process {:git-args "rev-parse --short HEAD"})
:timestamp (iso-now)})
(defn write-build-info [build-info]
(let [out-file (io/file CLASS_DIR BUILD_INFO)]
(io/make-parents out-file)
(spit out-file (pr-str build-info))))
;; https://clojure.org/guides/tools_build
;;
(defn javac [{basis :basis}]
(b/javac {:src-dirs [JAVA_SRC]
:class-dir CLASS_DIR
:basis (or basis (b/create-basis {:project "deps.edn"}))
:javac-opts ["-proc:none" "--release" "21"]
}))
(defn uberjar [_]
(let [build-info (build-info nil)
uber-file (io/file TARGET JAR_NAME)
basis (b/create-basis {:project "deps.edn"})]
(println "build:" build-info)
(write-build-info build-info)
(println "compile Java")
(javac {:basis basis})
(b/copy-dir {:src-dirs ["src" RESOURCES TARGET_RESOURCES]
:target-dir CLASS_DIR})
(println "compile Clojure")
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir CLASS_DIR
})
(println "pack uberjar")
(b/uber {:class-dir CLASS_DIR
:uber-file (str uber-file)
:basis basis
:main MAIN_CLASS})
(println "complete:" (str uber-file))
,))