tools-build

liebs 2022-10-30T21:38:28.218099Z

Using tools-build for the first time and my tests start running but then compilation fails with this error:

Execution error (FileNotFoundException) at build/loading (build.clj:1).
Could not locate clojure/tools/build/api__init.class, clojure/tools/build/api.clj or clojure/tools/build/api.cljc on classpath.
Not really sure what this means. I am using the uberjar instructions on the tools-build guide, minimally modified to reflect my usecase.

Alex Miller (Clojure team) 2022-10-30T21:47:07.950069Z

Can you post your deps.edn and build.clj in snippets here?

Alex Miller (Clojure team) 2022-10-30T21:47:20.874199Z

And the command you ran?

liebs 2022-10-30T21:51:25.885549Z

deps.edn:

{:paths ["."]
 :deps {org.clojure/clojure {:mvn/version "1.11.1"}}
 :aliases
 {;; Run with clj -T:build function-in-build
  :build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}}
          :ns-default build}}}
build.clj

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

(def lib 'bhlieberman/bitmap-transformer)
(def version (format "1.0.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

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

(defn uber [_]
  (clean nil)
  (b/copy-dir {:src-dirs ["./"]
               :target-dir class-dir})
  (b/compile-clj {:basis basis
                  :src-dirs ["./"]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :basis basis
           :main 'day-four.main}))
not much different from the example, but I do have a flat file structure bc I'm just using this simple project to learn about tools-build. That wouldn't be a problem, right?

liebs 2022-10-30T21:51:47.237729Z

also command was clj -T:build uber

seancorfield 2022-10-30T22:08:34.896789Z

@bhlieberman93 What does clojure -version say?

liebs 2022-10-30T22:09:08.863529Z

Clojure CLI version 1.11.1.1113

seancorfield 2022-10-30T22:10:51.676359Z

OK. Recent enough. The problem is your flat file structure: you are trying to compile-clj on . so it is trying to compile build.clj but using your project deps so tools.build is not available.

seancorfield 2022-10-30T22:11:58.362819Z

Do you have a src folder with day_four/main.clj in it?

liebs 2022-10-30T22:12:13.547299Z

I don't but I suppose I could make one

liebs 2022-10-30T22:12:23.537069Z

I was thinking the flat structure might cause issues

seancorfield 2022-10-30T22:12:24.549569Z

You have to in this case.

seancorfield 2022-10-30T22:12:46.430849Z

You don't want to treat build.clj as part of your code to be compiled into the uberjar.

seancorfield 2022-10-30T22:13:38.643069Z

Move day_four into src, then change both :src-dirs in build.clj to be ["src"] -- then build.clj won't be picked up by the copy/compile calls.

seancorfield 2022-10-30T22:14:33.364949Z

Oh, and change your deps.edn to remove :paths ["."] as well!

seancorfield 2022-10-30T22:14:48.765309Z

(it will default to ["src"] anyway)

liebs 2022-10-30T22:15:09.124279Z

Awesome, thanks a lot Sean!

seancorfield 2022-10-30T22:15:27.546399Z

NP. Glad to see another "convert" to tools.build 🙂