Fork me on GitHub
#tools-build
<
2022-10-30
>
Ben Lieberman21:10:28

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)21:10:07

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

Alex Miller (Clojure team)21:10:20

And the command you ran?

Ben Lieberman21:10:25

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?

Ben Lieberman21:10:47

also command was clj -T:build uber

seancorfield22:10:34

@U03QBKTVA0N What does clojure -version say?

Ben Lieberman22:10:08

Clojure CLI version 1.11.1.1113

seancorfield22:10:51

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.

seancorfield22:10:58

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

Ben Lieberman22:10:13

I don't but I suppose I could make one

Ben Lieberman22:10:23

I was thinking the flat structure might cause issues

seancorfield22:10:24

You have to in this case.

seancorfield22:10:46

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

seancorfield22:10:38

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.

seancorfield22:10:33

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

seancorfield22:10:48

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

Ben Lieberman22:10:09

Awesome, thanks a lot Sean!

seancorfield22:10:27

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