polylith

https://polylith.gitbook.io/ and https://github.com/polyfy/polylith
seancorfield 2021-06-26T05:03:36.142700Z

Started exploring the idea of migrating all our legacy artifacts into projects in our monorepo, even though we're still very early on the refactoring of the overall codebase. Looks very promising: I can just declare that the project depends on the (legacy) subproject that is the main entry point, treating it as a "base" even though it isn't in the Polylith structure (yet!). In tandem with this we're looking at replacing at least parts of our build shell script with a Clojure build.clj script of some sort, with an eye on the upcoming tools.build (that Alex talked about at clojureD) -- we're already taking advantage of being able to run multiple exec functions via -X in the latest CLI prerelease (1.10.3.882).

3
🚀 4
tengstrand 2021-06-27T16:53:38.150600Z

Nice!

domparry 2021-06-29T09:54:19.151800Z

Great going Sean. How many projects do you have to migrate in total? Or is the 16 all of the already?

seancorfield 2021-06-29T16:13:07.152300Z

@domparry We had 14 artifacts that we built for deployment, so those are all projects now, plus development, plus a dev-only tool which I hadn't considered as a candidate for a projects entry until yesterday. So that's "everything" converted in terms of buildable artifacts as projects. But my plan is to pull apart several of our larger artifacts into smaller projects: we have multiple -main functions in our codebase and we run some of them via java -cp the.jar the.main-ns rather than java -jar the.jar, so I plan to get us away from that by adding more projects.

1
seancorfield 2021-06-29T16:13:35.152500Z

(since I can just designate a JAR to build and a :main-class to use)

seancorfield 2021-06-29T16:14:42.152700Z

Then I plan to break apart all those -main namespaces from our legacy projects and those will become bases. That was actually my intention when I started this work, but I got distracted by converting our build system from several shell scripts to a single Clojure script instead 😐

domparry 2021-06-29T16:17:56.152900Z

That's inspiring. I think we are going to dedicate more focused effort on migrating to poly from now on.

1
seancorfield 2021-06-26T05:04:36.143600Z

I suspect I'll start pulling all our our -main functions out into bases fairly soon as part of this work and, yes, more blog posts will accompany it all.

📚 3
seancorfield 2021-06-26T08:00:53.145600Z

(defn uberjars [& projects]
  (doseq [p projects]
    (let [uberjar  (requiring-resolve 'hf.depstar.uberjar/build-jar)]
        (with-dir (io/file (str (System/getProperty "user.dir") "/projects/" p))
          (uberjar (-> (calc-project-basis) :aliases :uberjar :exec-args
                       ;; cater for being _above_ the project dir:
                       (update :jar #(str "projects/" p "/" %)))))))))
A function that can be run at the top of the workspace to build uberjars in projects, assuming each project uses depstar and has an :uberjar alias that can be invoked with -X.

seancorfield 2021-06-26T08:01:31.145700Z

(defn- calc-project-basis []
  (let [{:keys [root-edn project-edn]} (t/find-edn-maps)
        deps  (t/merge-edns [root-edn project-edn])]
    (t/calc-basis deps {})))
(assumes clojure.tools.deps.alpha :as t)

seancorfield 2021-06-26T08:02:05.145900Z

and [clojure.tools.deps.alpha.util.dir :refer [with-dir]]

tengstrand 2021-06-26T13:08:05.148400Z

Cool! This will be interesting to follow 🙂