Fork me on GitHub
#tools-deps
<
2021-09-24
>
rgm16:09:59

I have a question about how a lib’s resources get rolled up into an uberjar: • let’s say I’m beginning a new lib under /lib/foo/ within the project, and it has /lib/foo/deps.edn and /lib/foo/resources/hug.sql • The outer project is consuming it using :local/root in its deps.edn • Let’s say using depstar or now tools.build, would the uberjar contain hug.sql (the lib’s resource) by default?

rgm16:09:41

I have a couple plot twists here (eg lein with lein-tools-deps for … reasons), and I don’t think I understand classpath/build stuff all that well.

rgm16:09:16

(suppose now that I’ve boiled it down like that I could check it fairly easily)

rgm16:09:21

(doing that)

Alex Miller (Clojure team)16:09:51

there is no "by default" under tools.build - either can be done, depends what you're doing

rgm17:09:59

ah ok I was using the uberjar script in the tools.build guide

Alex Miller (Clojure team)17:09:38

that script is copying things from resources to the classes dir which is included into the uber jar

Alex Miller (Clojure team)17:09:09

so I think the answer is yes, it should be included

rgm17:09:17

my experiment seems to indicate: yes, the nested resources will get yanked in

seancorfield17:09:34

build-clj makes some assumptions about what's "typical": copy src + resources; compile src. But in general you have complete control.

rgm17:09:32

ok so the problem I’m having with my local/root lib resources not getting rolled up is probably some mismatch weirdness deep in lein-tools-deps and I can work around it by adding "lib/foo/resources" to the :resource-paths in project.clj

rgm17:09:59

(until such time as I can retire lein out of the project entirely)

seancorfield17:09:59

lein-tools-deps -- there's your problem 🙂

rgm17:09:23

ha well it’s providing a nice stepping stone in the middle of the river

rgm17:09:56

honestly this has been the only rough edge so far

seancorfield17:09:59

I archived boot-tools-deps because it only worked in the simplest cases and just caused confusion and frustration beyond those -- and I see a lot of the same around lein-tools-deps (although I think lein is slightly more amenable to such surgery).

seancorfield17:09:49

It's been about six years since I last used lein for anything other than helping beginners with problems... 🤷:skin-tone-2:

rgm17:09:12

ha well, yeah, I started the project in 2015 so that checks out

rgm17:09:51

verdict: yes, uberjar contains hug.sql from the local/root lib. Committed the experiment in case this is useful to anyone https://github.com/rgm/experiments/tree/master/2021/09-tools-build

rgm18:09:22

oh right on! Thanks for this and, frankly, all you do.

seancorfield18:09:31

At work, we build our uberjars like this:

(bb/clean {})
          (b/copy-file {:src version-clj
                        :target "target/classes/ws/uberjar/release.clj"})
          (bb/uber {:main main-class :uber-file jar
                    :compile-opts {:direct-linking true}})
the version-clj file is just a ns we create with a single def that has the git SHA/tag as its value, so we can ask any uberjar what it was built from.

seancorfield18:09:47

(spit version-clj (str "(ns ws.uberjar.release)"
                           "(def version \"" (git-version) "\")"))

seancorfield18:09:56

(defn git-version
  "Return a git version string"
  []
  (sh "git" "describe" "--tags" "--match" "b[ui][il]l[di]*"))

dorab21:09:21

I do something similar for the version. The uber task in my build.clj writes out a version.edn in the resources directory which is then read by the config management library (`aero` in this case) on startup.

2
john-shaffer18:09:14

How can I work around a transitive dep on a https://ask.clojure.org/index.php/7836/tools-deps-does-not-handle-maven-relocations?show=7836 package? One of tess4j's deps pulls in bouncycastle/bctsp-jdk14 somewhere. How can I find which package pulls it in so I can override it?

Alex Miller (Clojure team)18:09:55

This is not particularly easy right now

Alex Miller (Clojure team)18:09:21

You could exclude it in all of your top level deps, then -Stree I think

john-shaffer18:09:12

Thanks, I didn't know about -Stree

john-shaffer18:09:52

I was always using trace

john-shaffer18:09:24

Oh, hmm, trace is working okay now too. I think I just messed up the exclusion earlier. Sorry about that