tools-build

emccue 2021-11-09T17:16:36.189700Z

Using this script

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

(defn -main
  "Builds an uberjar"
  [& _]
  (let [class-dir "target/classes"
        uber-file "target/ic-standalone.jar"
        opts      {:class-dir    class-dir
                   :compile-opts {:direct-linking false}
                   :main         'company.web.server.main
                   :uber-file    uber-file
                   :exclude      ["license(.)*"]}]
    (b/delete {:path class-dir})
    (bb/uber opts)
    (println "Uberjar is built.")
    opts))
I get an uberjar but one of the namespaces that is loaded dynamically isn’t there

Alex Miller (Clojure team) 2021-11-09T17:18:26.190800Z

bb/uber will compile things in your :src-dirs

seancorfield 2021-11-09T17:19:00.191200Z

@emccue One of the namespaces in your own codebase? Is it under src or some other folder? bb/uber does

(println "Copying" (str (str/join ", " src+dirs) "..."))
    (b/copy-dir {:src-dirs   src+dirs
                 :target-dir class-dir})

emccue 2021-11-09T17:19:53.192200Z

it is in shared-src

:paths     ["src"
            "ui-src"
            "shared-src"
            "resources"]

Alex Miller (Clojure team) 2021-11-09T17:20:18.192900Z

I think you need to set :src-dirs then to include it in compilation

seancorfield 2021-11-09T17:20:18.193Z

Ah, OK, you need to tell the build about that then -- by default it just uses src.

emccue 2021-11-09T17:20:40.193200Z

okay

emccue 2021-11-09T17:20:59.194Z

is there a way to pull it out of the deps edn’s basis or is this just a place i need to specify

seancorfield 2021-11-09T17:21:32.194400Z

bb/uber assumes src + resources for copying but you can override :src-dirs and :resource-dirs for bb/uber.

seancorfield 2021-11-09T17:22:44.195300Z

bb/uber is just a shorthand for what's in the tools.build Guide:

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

seancorfield 2021-11-09T17:23:21.195900Z

If you want additional files copied into the classes folder, you need to tell the build about it.

seancorfield 2021-11-09T17:25:01.196800Z

Add it to your opts hash map in your -main (kind of weird to use -main in build.clj BTW -- the expected usage is clojure -T:build <task>).