tools-build

AustinP 2021-09-28T00:11:09.413800Z

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

seancorfield 2021-09-28T00:25:02.417700Z

@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.

seancorfield 2021-09-28T00:25:46.418600Z

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

seancorfield 2021-09-28T00:28:49.419700Z

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

seancorfield 2021-09-28T00:29:42.419800Z

@apaine13

(! 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 [org.corfield.build :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)
      (bb/clean)
      (bb/uber)))

(! 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?

seancorfield 2021-09-28T00:31:06.420Z

This uses my build-clj wrapper to simplify the uber function but under the hood it's basically just what's in the tools.build guide on http://clojure.org -- see https://github.com/seancorfield/build-clj/blob/main/src/org/corfield/build.clj#L207-L215

AustinP 2021-09-28T00:52:14.420300Z

Thanks for posting this Sean. The clj-new build.clj is helpful, I was trying to get mine going with the "basic" tools.build 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

AustinP 2021-09-28T00:55:38.420500Z

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

AustinP 2021-09-28T01:00:13.420700Z

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.

AustinP 2021-09-28T01:02:32.420900Z

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?

seancorfield 2021-09-28T01:03:30.421100Z

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

seancorfield 2021-09-28T01:04:03.421300Z

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

seancorfield 2021-09-28T01:06:16.421600Z

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"})

seancorfield 2021-09-28T01:07:45.422Z

Several tools.build 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).

AustinP 2021-09-28T01:11:45.422200Z

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 tools.build?

AustinP 2021-09-28T01:12:35.422400Z

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

seancorfield 2021-09-28T01:26:34.422600Z

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

seancorfield 2021-09-28T01:26:59.422800Z

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"}}

seancorfield 2021-09-28T01:28:07.423Z

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

seancorfield 2021-09-28T01:28:56.423200Z

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.

seancorfield 2021-09-28T01:29:19.423400Z

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

AustinP 2021-09-28T20:27:07.425800Z

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!!

seancorfield 2021-09-28T21:41:41.426Z

@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.