tools-build

wactbprot 2021-09-06T08:56:44.050400Z

@hiredman Fine! If ./target/classes is correct, config.edn is there which means that, as you say, something is wrong with compiling.

wactbprot 2021-09-06T09:03:33.052800Z

So, how do I ensure that ./target/classes is on the classpath at the clj -T:build uber step?

seancorfield 2021-09-06T10:11:52.053500Z

@wactbprot can you share your build script?

wactbprot 2021-09-06T10:19:17.054700Z

Sure, its more or less the same as in the guide:

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

(def lib 'com.github.wactbprot/repliclj)
(def version (format "0.2.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))

(def jar-file (format "target/%s-%s.jar" (name lib) version))

(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

(defn clean [_]
  (b/delete {:path "target"}))

(defn prep [_]
  (b/write-pom {:class-dir class-dir
                :lib lib
                :version version
                :basis basis
                :src-dirs ["src"]})
  (b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir}))

(defn jar [_]
  (b/write-pom {:class-dir class-dir
                :lib lib
                :version version
                :basis basis
                :src-dirs ["src"]})
  (b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
  (b/jar {:class-dir class-dir
          :jar-file jar-file}))

(defn uber [_]
  (b/compile-clj {:basis basis
                  :src-dirs ["src"]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :basis basis}))

wactbprot 2021-09-06T10:44:46.057300Z

Got it! If I use the top level :path and :deps in my deps.edn everything works fine ๐ŸŽ‰ How would I include an alias in the command clj -T:build uber?

borkdude 2021-09-06T10:47:19.057600Z

@wactbprot does -T:alias:build work?

wactbprot 2021-09-06T11:02:11.060700Z

@borkdude No, I have defined the deps and paths in a :dev alias that needs to be considered during the build uber step. However, for this project it is not important to use an alias; I am just happy that it works and curious how to include an alias in the build process.

Alex Miller (Clojure team) 2021-09-06T12:58:19.062400Z

What is the intent of the alias? To add deps? If so, In the build.clj you can compute a second basis and supply an alias when you do so

wactbprot 2021-09-06T13:02:08.063600Z

@alexmiller it is not important for this project but let's assume I like to add deps via an alias. How would this work?

Alex Miller (Clojure team) 2021-09-06T13:02:28.063900Z

Like I just said

Alex Miller (Clojure team) 2021-09-06T13:03:52.065800Z

If you want to parameterize your build program, you can do that too by having your entry point function take the alias to use while making the basis used during uberjaring

Alex Miller (Clojure team) 2021-09-06T13:04:31.066600Z

There is an example of parameterization in the build guide too

Alex Miller (Clojure team) 2021-09-06T13:05:53.068500Z

The important thing here is the command you are running at the cli is the build program. In the program, itโ€™s up to you what you do, what deps you use, how the program is parameterized

wactbprot 2021-09-06T13:10:14.070Z

ok, I see. A big thank you to all of you!

wactbprot 2021-09-06T13:21:41.072900Z

I missed the :aliases option the create-basis function provides. This works fine: (def basis (b/create-basis {:project "deps.edn" :aliases [:dev]})) Maybe it's an idea to add a hint under the "Some things to notice:" section in the guide. Thanks again!

borkdude 2021-09-06T13:37:29.073500Z

@alexmiller what if you want to add deps to use in build.clj and not as a top level dependency, how would that work?

Alex Miller (Clojure team) 2021-09-06T13:38:31.073900Z

isn't that the scenario we're discussing?

Alex Miller (Clojure team) 2021-09-06T13:39:27.074600Z

you're making the basis in the build.clj - if you want it to be something, pass the args to make it whatever you need it to be

borkdude 2021-09-06T13:43:39.075300Z

I mean, not the basis to use for e.g. building an uberjar, but additional tools like library-whatever to do whatever during the build

borkdude 2021-09-06T13:44:21.075500Z

I guess just use the :build alias? https://github.com/seancorfield/honeysql/blob/ec758dd818bf603b6eea2bfe042ff3133e72c93f/deps.edn#L6 That's pretty evident, I guess ;)

Alex Miller (Clojure team) 2021-09-06T13:56:53.076100Z

Yes

Eddie 2021-09-06T22:40:30.079300Z

@seancorfield I just came across your code in the comments of https://clojure.atlassian.net/browse/TBUILD-6 and it sparked hope that -X style tasks might be supported in build-clj. Is that on the horizon?

seancorfield 2021-09-06T22:44:20.082100Z

My impression, from talking to @alexmiller, is that some variant of this might end up in some Contrib library perhaps and then I would adjust build-clj to leverage that as needed. I don't want to bake our version in from work because it relies on things that are "unknowable" out in the wild (we vendor the Clojure CLI into our repo so that we can rely on a specific version being available on each tier as we roll out builds so we know where the correct version of exec.jar is on every machine).

seancorfield 2021-09-06T22:45:20.082800Z

(and exec.jar is an undocumented, unsupported, unstable API that could -- and has -- change at will right now)

seancorfield 2021-09-06T22:45:33.083100Z

Does that answer your Q @erp12?

Eddie 2021-09-06T22:49:46.085900Z

Yup, thanks @seancorfield. It sounds like things are in motion so I will allow my hack to stay a hack. I just want to trigger doc generation on an "prepare-release" entrypoint and (sh "clj" "-X:codox") does the trick.

seancorfield 2021-09-06T23:44:33.086900Z

@erp12 Yeah, in the absence of built-in exec-command style invocation, shelling out to the clojure script is probably reasonable...