tools-build

jumar 2022-11-25T09:55:40.989339Z

I haven't been using tools-build much in the past so I'm trying to learn it a bit. I've just generated a new project using clj-new

clojure -Tclj-new lib :name myname/mylib
Now, I can run a REPL within my Emacs (Cider) and play with the app. However, I'm wondering how should I iterate on the build script itselfs (build.clj)? When I run the standard repl build-clj isn't available. Should I run clj -A:build?

jumar 2022-11-25T09:56:41.508619Z

If I do that I don't seem to be able to require the build ns:

clj -A:build
...
(require 'build)
Execution error (FileNotFoundException) at user/eval1 (REPL:1).
Could not locate build__init.class, build.clj or build.cljc on classpath.

jumar 2022-11-25T10:00:41.527059Z

The guide says this: https://clojure.org/guides/tools_build > • This is just normal Clojure code - you can load this namespace in your editor and develop it interactively at the REPL. But it doesn't say anything about how to do that. Using clj -A:build I can at least require tools.build API:

(require '[clojure.tools.build.api :as b]
But what about the build ns itself?

jumar 2022-11-25T10:16:50.894329Z

Looking in the cider docs now I tried: https://docs.cider.mx/cider/basics/middleware_setup.html#using-tools-deps

:cider-build {:deps {io.github.seancorfield/build-clj
                       {:git/tag "v0.8.2" :git/sha "0ffdb4c"}}
                ;; see 
                ;; - check  for the newest version
                :extra-deps {cider/cider-nrepl {:mvn/version "0.28.7"}}
                :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]
                :ns-default build}
Then
clj -M:build
nREPL server started on port 52326 on host localhost - 
Then cider-connect from within Emacs. That kinda works I suppose - it's a bit tricky to manage but standard app REPL and the "build" REPL but it seems to be loading.

borkdude 2022-11-25T11:45:30.246729Z

@jumar You can explicitly add the current dir the the classpath with :paths ["."]

borkdude 2022-11-25T11:46:04.272439Z

or you can do this: clj -Scp $(`clojure -Spath -A:build:whatever-else` )

jumar 2022-11-25T13:29:36.999319Z

Oh I see, then maybe it's better to move build.clj to a separate directory (like build/build.clj)

seancorfield 2022-11-25T20:18:56.338349Z

Or just eval the build.clj file in your editor -- it shouldn't matter whether it's on the path or not.

👍 1
jumar 2022-11-26T04:57:52.122839Z

Yes, once i got cider repl working that became a perfect alternative:)

jumar 2022-11-26T05:02:03.731029Z

Btw. Thanks Sean for the tooling around deps. I also found deps-new and ended up using it The other tool I liked was tools.project from Exoscale but it was quite slow when executing build tasks and looked less flexible/ more opinionated

👍🏻 1