tools-build

agorgl 2025-06-13T17:20:24.719729Z

Why most of the tools.build compile-clj usages I see have either before or after a copy-dir with the "src" dir along the "resources"? E.g. from the official https://clojure.org/guides/tools_build:

(b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
  (b/compile-clj {:basis @basis
                  :ns-compile '[my.lib.main]
                  :class-dir class-dir})
Or from deps-new https://github.com/seancorfield/deps-new/blob/515dd2547bcdd5890a8fbf64e2ce26c088e1c93f/resources/org/corfield/new/app/build/build.tmpl#L36:
(b/copy-dir {:src-dirs ["resources" "src"] :target-dir class-dir})
    (b/compile-clj { ... :class-dir class-dir :src-dirs ["src"] ... })
I thought that when (pre)compiling clojure code the original sources are redundant, and that maybe they shouldn't be included in the copy-dir :src-dirs?

Alex Miller (Clojure team) 2025-06-13T17:32:11.835629Z

You dont necessarily need to copy the the src

Alex Miller (Clojure team) 2025-06-13T17:32:44.218199Z

But if you’re going to use the doc function etc those require the src files

agorgl 2025-06-13T18:08:30.813329Z

Ah I see, it makes sense

agorgl 2025-06-13T18:08:52.685839Z

I suppose they are also needed for the stack traces?

2025-06-13T18:13:04.743439Z

no

2025-06-13T18:13:32.242659Z

they aren't actually needed for doc either, but for source

agorgl 2025-06-13T18:14:20.541069Z

Ah that makes sense, thank you for the info!

2025-06-13T18:15:48.955619Z

I imagine it is mostly included in the examples because it is what other clojure build tools (like lein) do by default

seancorfield 2025-06-13T19:39:02.576999Z

If your main ns doesn't transitive reach all your source files -- perhaps because one or more nses are dynamically required at runtime -- then you'll need to copy those files (since they won't be compiled). I think Clojure itself has one of these (the instant time stuff?).

Alex Miller (Clojure team) 2025-06-13T20:33:59.390439Z

That was true at one point, but has not been for a while

seancorfield 2025-06-13T20:47:04.537109Z

Because we no longer have to support JDK 7 and earlier, right?

👍 1
seancorfield 2025-06-13T20:47:39.807939Z

(I have projects that have dynamically required nses so those don't get transitively compiled, as I recall)