Fork me on GitHub
#tools-build
<
2021-11-09
>
emccue17:11:36

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)17:11:26

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

seancorfield17:11:00

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

emccue17:11:53

it is in shared-src

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

Alex Miller (Clojure team)17:11:18

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

seancorfield17:11:18

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

emccue17:11:59

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

seancorfield17:11:32

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

seancorfield17:11:44

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

seancorfield17:11:21

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

seancorfield17:11:01

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