-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.clj
74 lines (58 loc) · 2.81 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
(ns build
(:require
[clojure.java.io :as io]
[clojure.tools.build.api :as b]
[clojure.tools.deps :as t]
[clojure.tools.deps.util.dir :refer [with-dir]]))
(def default-version "0.0.0-alpha-SNAPSHOT")
(def target-dir "target")
(def class-dir (str target-dir "/" "classes"))
(defn- get-project-aliases
[]
(let [edn-fn (juxt :root-edn :project-edn)]
(-> (t/find-edn-maps)
(edn-fn)
(t/merge-edns)
:aliases)))
(defn- ensure-project-root
"Given a task name and a project name, ensure the project
exists and seems valid, and return the absolute path to it."
[task project]
(let [project-root (str (System/getProperty "user.dir") "/projects/" project)]
(when-not (and project
(.exists (io/file project-root))
(.exists (io/file (str project-root "/deps.edn"))))
(throw (ex-info (str task " task requires a valid :project option") {:project project})))
project-root))
(defn uberjar
[{:keys [project uber-file] :as opts}]
(let [project-root (ensure-project-root "uberjar" project)
aliases (with-dir (io/file project-root) (get-project-aliases))
main (-> aliases :uberjar :main)
version (-> aliases :uberjar :version)]
(when-not main
(throw (ex-info (str "the " project " project's deps.edn file does not specify the :main namespace in its :uberjar alias")
{:aliases aliases})))
(when-not version
(println (str "*Warning*. The " project " project's deps.edn file does not specify a :version. The default of :version is being used.")
{:version default-version}))
(b/with-project-root project-root
(let [version (or version default-version)
uber-file (or uber-file
(-> aliases :uberjar :uber-file)
(str target-dir "/" project "-" version ".jar"))
basis (b/create-basis)
opts (merge opts
{:basis basis
:class-dir class-dir
:compile-opts {:direct-linking true}
:main main
:ns-compile [main]
:uber-file (str uber-file)})]
(b/delete {:path class-dir})
(println "\nCompiling" (str main "..."))
(b/compile-clj opts)
(println "Building uberjar" (str uber-file "..."))
(b/uber opts)
(println "Uberjar is built.")
opts))))