Fork me on GitHub
#tools-build
<
2021-12-20
>
fabrao10:12:06

Hello, if I understood, I have to include build.clj into src path of my project. I don´t know if it´s a dumb question but, when I try to run clj -T:build uber it´s getting Namespace could not be loaded: build. What am I missing?

borkdude10:12:12

tools.build normally expects the build.clj file in the root of the project, although I think src should work too. do you have (ns build ...) in the file?

fabrao10:12:23

hello, yes . I´ll change it to root of project and try again

fabrao10:12:18

it seems that in src it´ll not work.

borkdude10:12:47

maybe add :extra-paths ["src"] to the build alias

borkdude10:12:00

if you really want to have it under src

fabrao10:12:09

no, I´m not

borkdude10:12:34

As mentioned above, running a tool with -T removes the project :paths and :deps. Using -T:build will use only the :paths and :deps from the :build alias. The root deps.edn is still included, which will pull in Clojure as well (but it would also come in as a dependency of tools.build). The :paths are not specified here, so no additional paths are added, however, -T includes the project root "." as a path by default.

So executing clj -T:build jar will use an effective classpath here of:

"."

clojure (from the root deps.edn)

tools.build (from the :build alias :deps)

the transitive dependencies needed by clojure and tools.build

fabrao10:12:18

Yes, that because I use

(ns build
  (:require [clojure.tools.build.api :as b]))

(def lib 'mylib/lib)
(def version (format "1.2.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

(defn clean [_]
  (b/delete {:path "target"}))

(defn uber [_]
  (clean nil)
  (b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
  (b/compile-clj {:basis basis
                  :src-dirs ["src"]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :basis basis
           :main 'mylib.core}))

borkdude10:12:54

Good luck, the explanation is above in the documentation :)

fabrao10:12:17

thank you for your time

fabrao18:12:03

I changed from depstar to tools.build and I observe that the final uberjar increase 20 Mb. What do you think is going to be?

hiredman18:12:34

I mean, as a rough sanity check maybe just count the files in both

hiredman18:12:05

jars are zipfiles, and can be created with varying levels of compression as well

fabrao18:12:59

so, do you think the difference is that one is zipped and the other not?

hiredman18:12:26

I dunno, I would start by checking the file counts

hiredman18:12:36

something like jar -tf your-uberjar.jar|wc -l