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.Can you post your deps.edn and build.clj in snippets here?
And the command you ran?
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?also command was clj -T:build uber
@bhlieberman93 What does clojure -version say?
Clojure CLI version 1.11.1.1113
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.
Do you have a src folder with day_four/main.clj in it?
I don't but I suppose I could make one
I was thinking the flat structure might cause issues
You have to in this case.
You don't want to treat build.clj as part of your code to be compiled into the uberjar.
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.
Oh, and change your deps.edn to remove :paths ["."] as well!
(it will default to ["src"] anyway)
Awesome, thanks a lot Sean!
NP. Glad to see another "convert" to tools.build 🙂