Last active
April 28, 2022 16:10
-
-
Save bsless/839bbf7b7ab73adfba6703e79c079cff to your computer and use it in GitHub Desktop.
Build independent Clojure module as part of same repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns build | |
(:refer-clojure :exclude [test]) | |
(:require | |
[clojure.tools.build.api :as b] | |
[org.corfield.build :as bb])) | |
(def version (format "0.0.%s" (b/git-count-revs nil))) | |
(def class-dir "target/classes") | |
(def modules | |
'{ | |
:module/aaa {:module/lib com.acme/module-a | |
:module/project-root "./module-a" | |
:module/prep-lib true} | |
:module/bbb {:module/lib com.acme/module-b | |
:module/project-root "./module-b"}}) | |
(defn -compile [{:keys [basis] :as opts}] | |
(println "Compiling") | |
(when (:module/prep-lib opts) | |
(b/javac {:src-dirs ["src/main/java"] | |
:class-dir class-dir | |
:basis basis | |
:javac-opts ["-source" "8" "-target" "8"]})) | |
opts) | |
(defn do-module | |
[opts m f] | |
(let [{:module/keys [lib project-root]} m] | |
(binding [b/*project-root* project-root] | |
(println "Switching to module" lib "in" b/*project-root*) | |
(let [basis (b/create-basis {:project "./deps.edn"}) | |
opts (assoc (merge opts m) :lib lib :basis basis)] | |
(f opts))))) | |
(defn do-modules | |
[opts f] | |
(let [opts (assoc opts :version version)] | |
(doseq [[_ m] modules] | |
(do-module opts m f)) | |
opts)) | |
(defn compile-modules | |
[opts] | |
(do-modules opts -compile)) | |
(defn build-modules | |
[opts] | |
(do-modules | |
(assoc opts :version version) | |
#(-> % | |
(assoc :version version) | |
(bb/clean) | |
(-compile) | |
(bb/jar)))) | |
(comment | |
(build-modules nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment