Fork me on GitHub
#tools-deps
<
2022-04-21
>
Jem McElwain16:04:34

does anyone have an example or suggestions for how to structure a "multi-module" project using tools.build? ideally, i would like to have a single build.clj from a root directory that's able to build jars of sub-projects in a consistent way, but i'm running into lots of problems trying to get this to work. wondering if anyone has advice on best practices here.

seancorfield17:04:57

Happy to try to help if you can provide more info about what you tried and what doesn't work. We have a monorepo and build over a dozen uberjars from it using a single build.clj at the root. Here's an excerpt from our uberjars task:

(doseq [p projects]
      (println "\nRunning: uber on" p)
      (let [project-dir (str "projects/" p)
            aliases     (with-dir (io/file project-dir) (get-project-aliases))]
        (binding [b/*project-root* project-dir]
          (bb/clean {})
          (bb/uber (assoc (:uberjar aliases)
                          :compile-opts {:direct-linking true})))))
b is tools.build and bb is my org.corfield.build library but it's only a very thin wrapper around tools.build providing "sane" defaults.

seancorfield17:04:17

Each projects/<foo> folder has its own deps.edn to specify the deps needed for the uberjar (mostly just :local/root to other parts of the monorepo) and there's an :uberjar alias containing data -- options -- for the uber task.

❤️ 1
seancorfield17:04:56

(defn- get-project-aliases []
  (let [edn-fn (juxt :root-edn :project-edn)]
    (-> (t/find-edn-maps)
        (edn-fn)
        (t/merge-edns)
        :aliases)))
is the t.d.a-based helper for getting aliases out of the project's deps.edn file.

seancorfield17:04:00

(our monorepo is slowly migrating from an ad hoc approach to using Polylith which has helped a lot with separating out "build" concerns from dev/runtime concerns)

Adam Helins07:04:40

@U02AEH4M8GY I wrote a little helper for exactly that kind of setup and used it successfully in several projects. Just have to properly document it though 😅 I'm curious, what have you tried?

Jem McElwain23:04:26

Major problem was just that we were using 7.5.0, most things were fixed just by just upgrading to the latest version and using some of the provided build.clj as reference. Also had some issues with b/write pom skipping local deps, but realized that could be solved by providing extra deps.edn when creating basis.

Alex Miller (Clojure team)16:04:56

should be fine, just need to be careful with calling b/set-project-root! in each per-project context

Alex Miller (Clojure team)16:04:19

there's been at least one thread about this in #tools-build