Fork me on GitHub

Correct, all the paths in my deps.edn have ../.. ahead of them, pointing up the filesystem to bases and components


@apaine13 In a Polylith project, you should just be able to cd projects/whatever && clojure -T:build uber with just a bare bones build.clj script and it should "just work". Your project's deps.edn file should have all the deps declared that it needs and you just create a basis and run uber with that and declaring the main class -- there's nothing to copy, generally, with Polylith since projects folders have no src or resources in a lot of cases.


It might be better to take this to the #polylith channel -- we use with Polylith at work and it works just fine.


I'm going to post a shell session in a thread of creating a Polylith workspace (using clj-new) and building the uberjar with so you can see the build.clj and deps.edn files involved...



(! 812)-> clojure -Tclj-new polylith :name austin/p
Generating a project called p based on the 'polylith' template.
Initialized the project for use with 'git'.

(! 813)-> cat p/projects/p/build.clj 
(ns build
  (:refer-clojure :exclude [test])
  (:require [ :as bb]))

(def lib 'net.clojars.austin/p)
(def version "0.1.0-SNAPSHOT")
(def main 'austin.p.cli.main)

(defn uber "Build the uberjar." [opts]
  (-> opts
      (assoc :lib lib :version version :main main)

(! 814)-> cat p/projects/p/deps.edn 
{:paths [] ; no src or resources

 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        poly/component-greeter {:local/root "../../components/greeter"}
        poly/base-cli {:local/root "../../bases/cli"}}

 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}

           :build {:deps {io.github.seancorfield/build-clj
                          {:git/tag "v0.4.0" :git/sha "54e39ae"}}
                   :ns-default build}}}

(! 815)-> (cd p/projects/p && clojure -T:build uber)

Cleaning target...

Writing pom.xml...
Skipping coordinate: {:local/root /Users/sean/clojure/fresh/p/components/greeter, :deps/manifest :deps, :deps/root /Users/sean/clojure/fresh/p/components/greeter, :parents #{[]}, :paths [/Users/sean/clojure/fresh/p/components/greeter/src /Users/sean/clojure/fresh/p/components/greeter/resources]}
Skipping coordinate: {:local/root /Users/sean/clojure/fresh/p/bases/cli, :deps/manifest :deps, :deps/root /Users/sean/clojure/fresh/p/bases/cli, :parents #{[]}, :paths [/Users/sean/clojure/fresh/p/bases/cli/src /Users/sean/clojure/fresh/p/bases/cli/resources]}
Copying src, resources...
Compiling austin.p.cli.main...
Building uberjar target/p-0.1.0-SNAPSHOT.jar...

(! 816)-> java -jar p/projects/p/target/p-0.1.0-SNAPSHOT.jar 
Hello, World!
Does that help?


This uses my build-clj wrapper to simplify the uber function but under the hood it's basically just what's in the guide on -- see


Thanks for posting this Sean. The clj-new build.clj is helpful, I was trying to get mine going with the "basic" to understand it before i grabbed your build-clj lib, but I might just try converting mine to build-clj and see if that solves anything


its interesting that i dont need to copy anything into target. So the basis that's created from the deps.edn knows of everything since its in the deps.edn, even in a polylith monorepo. My copying everything over could very well be whats throwing this all off. Let me try with just the basis and main class and see what happens


I think where mine got messy is I have config files in my project directory that the base needs to read from in order to compile. So I was getting build errors since it couldnt find those files, so I was trying to copy-dir everything into the same place, project dir and base src. Since the base is being used by multiple projects, each with a unique set of config files to be fed into the base at compile time.


So where in the build.clj is the right place to point to the project specific configs, so the base can compile? Or should we be structuring the monorepo differently in order to avoid this situation?


Each project should be complete and self-contained, so that's where you'd specify config stuff.


If you have a resources folder in your project, you may want :paths ["resources"] in your (project) deps.edn file (but with you probably don't need it, now I think about it).


The build-clj's uber task will copy that automatically. If you wanted it to do it yourself, you would (copy-dir {:src-dirs ["resources"] :target-dir "target/classes"})


Several tasks take the computed basis and that's how they find everything -- and that basis is computed from the project's deps.edn file (i.e., it's automatic if you have cd projects/whatever before you start).


I do have the project's resources listed in my deps.edn :paths after all the ../../components and ../../base. Why do you say I dont need that there with


hmm okay, if the build-clj's uber will grab all that correctly, and its all based on the basis, let me roll all this back and get on the simplest case using build-clj and see where i get. Will update here, appreciate all the help


You should not be using :paths for components or bases. You should be using :deps with :local/root


See the project deps.edn I posted above:

:deps {org.clojure/clojure {:mvn/version "1.10.3"}
        poly/component-greeter {:local/root "../../components/greeter"}
        poly/base-cli {:local/root "../../bases/cli"}}


The reason you don't need resources with is that you copy-dir from resources to target/classes and the uber task builds the JAR from target/classes.


If you wanted to run code directly from the projects/whatever folder -- or if the resources stuff was needed for running tests in the context of that project then, yes, you still need it in :paths in deps.edn there.


But those are two separate contexts: building a JAR vs running code.


So a large part of whatever was causing my previous issues was likely due to the fact that we've been putting off our migration to the latest Polylith, hence still having :paths and no :local/root in deps. Successfully migrated the workspace today, and after the dust settled, was able to get our projects happily uberjared with your simple build.clj from clj-new ! Much appreciate the help, and the creation and maintenance of such useful tools!!


@apaine13 Glad to hear it! When you mentioned :paths like that, I wondered if you were trying to target the older deps.edn version of Polylith. When we started our migration, we targeted the issue-66 branch, so we've been following the latest developments, which definitely made life easier.