Fork me on GitHub
#tools-build
<
2022-04-25
>
ossosoi loso12:04:55

Hi, I’m migrating from depstar 1.x to tools-build for building an uberjar. The uberjar resulting from tools-build gives, when running, a ClassNotFoundException for clojure.tools.logging.impl.LoggerFactory (log in thread). My original deps configuration was quite simple with only :extra-paths and :extra-deps from aliases. Any ideas?

ossosoi loso12:04:32

{:clojure.main/message “Execution error (ClassNotFoundException) at jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).\nclojure.tools.logging.impl.LoggerFactory\n”, :clojure.main/triage {:clojure.error/class java.lang.ClassNotFoundException, :clojure.error/line 641, :clojure.error/cause “clojure.tools.logging.impl.LoggerFactory”, :clojure.error/symbol jdk.internal.loader.BuiltinClassLoader/loadClass, :clojure.error/source “BuiltinClassLoader.java”, :clojure.error/phase :execution}, :clojure.main/trace {:via [{:type java.lang.NoClassDefFoundError, :message “clojure/tools/logging/impl/LoggerFactory”, :at [<redacted>.backend.main$_main invokeStatic “main.clj” 107]} {:type java.lang.ClassNotFoundException, :message “clojure.tools.logging.impl.LoggerFactory”, :at [jdk.internal.loader.BuiltinClassLoader loadClass “BuiltinClassLoader.java” 641]}], :trace [[jdk.internal.loader.BuiltinClassLoader loadClass “BuiltinClassLoader.java” 641] [jdk.internal.loader.ClassLoaders$AppClassLoader loadClass “ClassLoaders.java” 188] [java.lang.ClassLoader loadClass “ClassLoader.java” 520] [<redacted>.backend.main$_main invokeStatic “main.clj” 107] [<redacted>.backend.main$_main invoke “main.clj” 106] [clojure.lang.AFn applyToHelper “AFn.java” 152] [clojure.lang.AFn applyTo “AFn.java” 144] [clojure.lang.Var applyTo “Var.java” 705] [clojure.core$apply invokeStatic “core.clj” 667] [clojure.main$main_opt invokeStatic “main.clj” 514] [clojure.main$main_opt invoke “main.clj” 510] [clojure.main$main invokeStatic “main.clj” 664] [clojure.main$main doInvoke “main.clj” 616] [clojure.lang.RestFn applyTo “RestFn.java” 137] [clojure.lang.Var applyTo “Var.java” 705] [clojure.main main “main.java” 40]], :cause “clojure.tools.logging.impl.LoggerFactory”}}

Alex Miller (Clojure team)12:04:19

Not sure there is info here to tell. Seems like the Uber jar is missing something - can you look at the jar contents to get a sense of whether it mostly contains what you expect? (Like other deps). The uberjar deps should be based on the basis, which is effectively what you would see from clj -X:deps list :user nil

👍 1
Alex Miller (Clojure team)12:04:23

If that all looks fine, then I would wonder about whether you are doing aot with compile-clj

ossosoi loso18:04:24

Thanks! An update: Most deps seem to be in the jar. clj -X:common:backend:deps list :user nil only gives the stock clojure deps (none of my deps). With depstar v2 the following works clojure -X:uberjar :jar target/os.jar :aliases '[:common :backend]' . My b/compile-clj only differs by the basis which has the aliases from the uberjar command above. I added :gen-class to my main ns definition to no avail. I read on https://stackoverflow.com/questions/8291910/noclassdeffounderror-with-clojure-tools-logging that perhaps I should be compiling clojure.tools.logging.impl. I have not figured out how to do that yet. I think I might go to check depstar’s example projects next and see how they made the jump to tools-build

seancorfield18:04:28

(you should not need to do anything special for tools.logging)

ossosoi loso18:04:04

Does this look right?

(def basis (b/create-basis {:project "deps.edn"
                            :aliases [:common :backend]}))

seancorfield18:04:45

I think so, yes.

seancorfield18:04:01

(it looks like how we pass aliases to create-basis in our build.clj script at work)

ossosoi loso18:04:02

I don’t know what I did but I”m getting a different error when compiling now:

Syntax error (ClassNotFoundException) compiling at (/private/var/folders/wc/j7lkhy7n76zcgf1ccbvrv0lh0000gp/T/compile-clj6120235454022173811/compile.clj:1:1).
clojure.tools.reader.reader_types.Reader
Among many things I cleared the class dir. And added :gen-class

seancorfield18:04:34

Sounds like you have conflicting versions of tools.reader perhaps?

seancorfield18:04:54

What is in your :build alias in deps.edn?

ossosoi loso18:04:26

:build {:deps {io.github.clojure/tools.build {:git/tag “v0.8.1” :git/sha “7d40500"}} :extra-paths [“target/shadow/prod/resources” “dev-resources”] :paths [“./infra/app”] :ns-default “build”}

seancorfield18:04:06

Also maybe look at the output of clojure -X:deps tree :aliases '[:common :backend]' for references to tools.reader?

ossosoi loso18:04:35

Looks indeed like I have many versions of tools.reader as deps (of deps…). I’ll have to return to this tomorrow. Thanks for the help! EDIT: Looks like clojure.tools.logging.impl.LoggerFactory is still not found.

tstout00:02:46

@U02CC5T8LLU Did you resolve this? I'm facing a similar issue.