tools-build

fabrao 2021-12-20T10:15:06.335500Z

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?

borkdude 2021-12-20T10:18:12.335900Z

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?

fabrao 2021-12-20T10:20:23.336100Z

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

fabrao 2021-12-20T10:28:18.336300Z

it seems that in src it´ll not work.

borkdude 2021-12-20T10:28:47.336500Z

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

borkdude 2021-12-20T10:29:00.336700Z

if you really want to have it under src

fabrao 2021-12-20T10:30:09.336900Z

no, I´m not

borkdude 2021-12-20T10:31:34.337100Z

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

borkdude 2021-12-20T10:31:40.337300Z

https://clojure.org/guides/tools_build

fabrao 2021-12-20T10:34:18.337900Z

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

borkdude 2021-12-20T10:34:54.338100Z

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

fabrao 2021-12-20T10:35:17.338300Z

thank you for your time

fabrao 2021-12-20T18:17:03.339800Z

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?

2021-12-20T18:19:34.340900Z

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

2021-12-20T18:20:05.341400Z

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

fabrao 2021-12-20T18:24:59.342Z

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

2021-12-20T18:25:26.342500Z

I dunno, I would start by checking the file counts

2021-12-20T18:26:36.343100Z

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