-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.clj
116 lines (101 loc) · 3.18 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(ns monkey.build
"Opinionated functions for building Monkey Projects libraries"
(:require [clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))
(def target "target")
(def class-dir (str target "/classes"))
(defn- copy-sources [basis]
(println "Copying sources from:" (:paths basis))
(b/copy-dir {:src-dirs (:paths basis)
:target-dir class-dir}))
(defn clean
"Cleans target class directory"
[]
(println "Cleaning" class-dir)
(b/delete {:path class-dir}))
(defn jar
"Builds a JAR file"
[{:keys [jar main]}]
(let [basis (b/create-basis)]
(clean)
(copy-sources basis)
(println "Building a jar to" jar)
(b/jar {:class-dir class-dir
:jar-file jar
:main main})
(println "Done.")))
(defn- read-env [v]
(some-> v
(System/getenv)))
(defn- maybe-invoke [s]
(when-let [v (some-> s (find-var))]
(v)))
;; Determines the value of the version from the args. This checks the
;; `version`, `version-env` and `version-fn` params.
(def determine-version
(some-fn :version (comp read-env :version-env) (comp maybe-invoke :version-fn)))
(def ^:private next-snapshot "0.2-SNAPSHOT")
(defn env-or-default []
(or (System/getenv "VERSION") next-snapshot))
(defn install
"Installs JAR locally"
[{:keys [jar lib] :as args}]
(let [basis (b/create-basis)
version (determine-version args)
opts {:basis basis
:class-dir class-dir
:version version
:lib (symbol lib)}]
(println "Writing pom.xml for version" version)
(b/write-pom (assoc opts :src-dirs (:paths basis)))
(println "Installing" jar "to local mvn repo")
(b/install (assoc opts :jar-file jar))
(println "Done.")))
(defn jar+install [args]
(jar args)
(install args))
(defn pom
"Generates pom.xml file, with the given version"
[{:keys [lib scm] :as args}]
(let [basis (b/create-basis)
opts {:basis basis
:version (determine-version args)
:lib (symbol lib)
:target target
:scm scm}
pom "pom.xml"]
(println "Writing" pom)
(b/write-pom opts)
(b/copy-file {:src (str target "/" pom)
:target pom})))
(defn deploy
"Deploys the library to an external repo. If no repository is given,
it uses Clojars. Be sure to set `CLOJARS_USERNAME` and `CLOJARS_PASSWORD`
in that case."
[{:keys [jar repository] :as opts}]
(pom opts)
(println "Deploying" jar "to" (or repository "clojars"))
(dd/deploy (merge {:installer :remote
:artifact jar}
opts)))
(defn jar+deploy [args]
(jar args)
(deploy args))
(defn uberjar
"Creates an uberjar"
[{:keys [jar main]}]
(let [basis (b/create-basis)
opts {:uber-file jar
:basis basis
:class-dir class-dir
:main (when main (symbol main))}]
(clean)
(copy-sources basis)
(println "Compiling...")
(b/compile-clj {:basis basis
:src-dirs (:paths basis)
:class-dir class-dir
:compile-opts {:direct-linking true}})
(println "Creating uberjar" jar)
(b/uber opts)
(println "Done.")))