Fork me on GitHub
#tools-build
<
2022-08-03
>
defa09:08:09

Im trying to migrate a project from uberdeps/uberdeps to tools.build and was wondering how to deal with resources, like .edn files when building an uber-jar. My build.clj file contains something like this:

(def basis (b/create-basis {:project "deps.edn"
                            :aliases [:shared
                                      :component_a
                                      :component_b
                                      :service]}))
(def class-dir "target/classes")

(defn uber [_]

  ;(b/copy-dir {:src-dirs   [ ... resource-dirs-from-aliases ...]
  ;             :target-dir class-dir})

  (b/compile-clj {:basis     basis
                  :class-dir class-dir})

  (b/uber {:class-dir class-dir
           :uber-file "target/service.jar"
           :basis     basis
           :main      'service.main}))
but without the copy-dir explicitly listing the resource dirs that are declared as :extra-src in the aliases, they will not be part of jar file. I can collect these dirs from the basis but maybe there is a more straightforward way or am I missing something here?

defa09:08:09

my current solution is:

(b/copy-dir {:src-dirs   (->> basis
                                :classpath-args
                                :extra-paths
                                (filter #(clojure.string/ends-with? % "/resources")))
               :target-dir class-dir})

Alex Miller (Clojure team)12:08:22

Typically you want your resource dirs in your :paths (as they are part of the classpath), and then you will get them from the copy-dir

defa12:08:05

the resource dirs are in :extra-paths of each alias but the *.edn files in there will not be part of the uberjar

{:aliases {:component_a {:extra-paths ["src/component_a/clj" "src/component_a/resources"]}
...}

defa12:08:07

or is :extra-paths vs. :paths the problem?