Local lib not found by :local/root

i am trying to get the
Using local libraries
in the to work from the Deps and CLI Guide.

i’ve set things up exactly as written inside a directory called depscliguide2:
% tree
.
├── hello-world
│ ├── deps.edn
│ └── src
│ └── hello.clj
├── nolib
│ ├── deps.edn
│ └── src
│ └── sayhello.clj
└── time-lib
├── deps.edn
└── src
└── hello_time.clj

the nolib dir is just there to make sure that its deps.edn:

{:deps
 {clojure.java-time/clojure.java-time {:mvn/version "1.2.0"}}}

can actually grab the java-time 1.2.0 lib.

sayhello.clj is really hello.clj:

ns sayhello
  (:require [java-time.api :as t]))

(defn time-str
  "Returns a string representation of a datetime in the local time zone."
  [instant]
  (t/format
    (t/with-zone (t/formatter "hh:mm a") (t/zone-id))
    instant))

(defn run [opts]
  (println "Hello world, the time is" (time-str (t/instant))))

% clj -X sayhello/run
works just fine

the code in
time-lib
hello-world
has been copied from the web page (filenames use ‘_’ for ns with ‘-’ etc)

however, when i go into hello-world and
% clj -X hello/run
i get

Execution error (FileNotFoundException) at hello-time/eval234$loading (hello_time.clj:1).
Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Full report at:
/tmp/clojure-16741433504450784431.edn

/tmp/clojure-16741433504450784431.edn
doesn’t shed any further light beyond just repeating that it can’t locate the java-time lib.

if i copy hello.clj into time-lib/src and run it from there, everything works nicely.

so my conclusion is that the hello-time/deps.edn

{:deps
 {time-lib/time-lib {:local/root "../time-lib"}}}

is unable (for some mysterious reason) to find the java-time lib using the hello_time.clj:

ns hello-time
  (:require [java-time.api :as t]))

which is what the hello-world/deps.edn asks it to do:

{:deps
 {time-lib/time-lib {:local/root "../time-lib"}}}

i’m assuming there is something wrong with :local/root, but don’t know what (adjusting the …/ didn’t succeed) based on:

  1. the error message (FileNotFoundException).
  2. the fact that time-lib/src/hello.clj does work.

i also saw

Modify hello-world/deps.edn to use a local coordinate that refers to the root directory of the time-lib library (make sure to update the path for your machine)

but don’t know what they mean by “update the path” since i thought the deps.edn file is supposed to do just that.

why isn’t this working (especially since it is copied directly from the instructions on the webpage)?

Some of what you say in the prose doesn’t match the structure and/or filenames.

Perhaps you can put this project structure up on GitHub so we can see it exactly as it is and can figure out what is wrong?

much appreciated sean!

This works just fine for me:

(~/clojure/depscliguide2)-(!2004)-> (cd time-lib/ && clojure -X hello/run)
Hello world, the time is 08:36 AM

Tue Jul 11 08:36:56
(~/clojure/depscliguide2)-(!2005)-> (cd hello-world/ && clojure -X hello/run)
Hello world, the time is 08:37 AM

So I’m wondering what version of clojure you have installed?

(~/clojure/depscliguide2)-(!2006)-> clojure -version
Clojure CLI version 1.11.1.1347
% clojure -version
Clojure CLI version 1.11.1.1347

same as yours, sean.

on my archlinux:

% pacman -Ss clojure
extra/clojure 1.11.1.1347-1 [installed]
    Lisp dialect for the JVM

so i have the most recent version.

% cd hello-world/ && clojure -X hello/run
Execution error (FileNotFoundException) at hello-time/eval234$loading (hello_time.clj:1) …

(the other one, inside time-lib, works of course as indicated in the op.)

this is a mystery!

Try cd hello-world && clojure -Sforce -X hello/run just to see if your .cpcache folder got stale and the CLI didn’t think it needed to be updated.

same thing:

% cd clj/depscliguide2
schnell ~/clj/depscliguide2
%  hello-world && clojure -Sforce -X hello/run
Execution error (FileNotFoundException) at hello-time/eval234$loading (hello_time.clj:1).
Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Full report at:
/tmp/clojure-8678263492725868354.edn

i also tried after deleting the .cpcache folders and go the same error.

i’m including the full report, but i couldn’t find anything helpful there other than the line:
:message “Syntax error macroexpanding at (hello_time.clj:1:1).”,

since the error is showing up starting
line 1, column 1
that seems to suggest it is not happy with something connected to

(ns hello-time
  (:require [java-time.api :as t]))

which of course doesn’t explain why it works on your machine.

full report follows:

% cat /tmp/clojure-8678263492725868354.edn
{:clojure.main/message
 "Execution error (FileNotFoundException) at hello-time/eval234$loading (hello_time.clj:1).\nCould not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.\n",
 :clojure.main/triage
 {:clojure.error/class java.io.FileNotFoundException,
  :clojure.error/line 1,
  :clojure.error/cause
  "Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.",
  :clojure.error/symbol hello-time/eval234$loading,
  :clojure.error/source "hello_time.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.Compiler$CompilerException,
    :message "Syntax error macroexpanding at (hello_time.clj:1:1).",
    :data
    {:clojure.error/phase :execution,
     :clojure.error/line 1,
     :clojure.error/column 1,
     :clojure.error/source "hello_time.clj"},
    :at [clojure.lang.Compiler load "Compiler.java" 7665]}
   {:type java.io.FileNotFoundException,
    :message
    "Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.",
    :at [clojure.lang.RT load "RT.java" 462]}],
  :trace
  [[clojure.lang.RT load "RT.java" 462]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6908 invoke "core.clj" 6161]
   [clojure.core$load invokeStatic "core.clj" 6160]
   [clojure.core$load doInvoke "core.clj" 6144]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5933]
   [clojure.core$load_one invoke "core.clj" 5928]
   [clojure.core$load_lib$fn__6850 invoke "core.clj" 5975]
   [clojure.core$load_lib invokeStatic "core.clj" 5974]
   [clojure.core$load_lib doInvoke "core.clj" 5953]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$load_libs invokeStatic "core.clj" 6016]
   [clojure.core$load_libs doInvoke "core.clj" 6000]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$require invokeStatic "core.clj" 6038]
   [clojure.core$require doInvoke "core.clj" 6038]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [hello_time$eval234$loading__6789__auto____235
    invoke
    "hello_time.clj"
    1]
   [hello_time$eval234 invokeStatic "hello_time.clj" 1]
   [hello_time$eval234 invoke "hello_time.clj" 1]
   [clojure.lang.Compiler eval "Compiler.java" 7194]
   [clojure.lang.Compiler eval "Compiler.java" 7183]
   [clojure.lang.Compiler load "Compiler.java" 7653]
   [clojure.lang.RT loadResourceScript "RT.java" 381]
   [clojure.lang.RT loadResourceScript "RT.java" 372]
   [clojure.lang.RT load "RT.java" 459]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6908 invoke "core.clj" 6161]
   [clojure.core$load invokeStatic "core.clj" 6160]
   [clojure.core$load doInvoke "core.clj" 6144]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5933]
   [clojure.core$load_one invoke "core.clj" 5928]
   [clojure.core$load_lib$fn__6850 invoke "core.clj" 5975]
   [clojure.core$load_lib invokeStatic "core.clj" 5974]
   [clojure.core$load_lib doInvoke "core.clj" 5953]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$load_libs invokeStatic "core.clj" 6016]
   [clojure.core$load_libs doInvoke "core.clj" 6000]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$require invokeStatic "core.clj" 6038]
   [clojure.core$require doInvoke "core.clj" 6038]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [hello$eval228$loading__6789__auto____229 invoke "hello.clj" 1]
   [hello$eval228 invokeStatic "hello.clj" 1]
   [hello$eval228 invoke "hello.clj" 1]
   [clojure.lang.Compiler eval "Compiler.java" 7194]
   [clojure.lang.Compiler eval "Compiler.java" 7183]
   [clojure.lang.Compiler load "Compiler.java" 7653]
   [clojure.lang.RT loadResourceScript "RT.java" 381]
   [clojure.lang.RT loadResourceScript "RT.java" 372]
   [clojure.lang.RT load "RT.java" 459]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6908 invoke "core.clj" 6161]
   [clojure.core$load invokeStatic "core.clj" 6160]
   [clojure.core$load doInvoke "core.clj" 6144]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5933]
   [clojure.core$load_one invoke "core.clj" 5928]
   [clojure.core$load_lib$fn__6850 invoke "core.clj" 5975]
   [clojure.core$load_lib invokeStatic "core.clj" 5974]
   [clojure.core$load_lib doInvoke "core.clj" 5953]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$load_libs invokeStatic "core.clj" 6016]
   [clojure.core$load_libs doInvoke "core.clj" 6000]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$require invokeStatic "core.clj" 6038]
   [clojure.core$require doInvoke "core.clj" 6038]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.run.exec$requiring_resolve_SINGLEQUOTE_
    invokeStatic
    "exec.clj"
    36]
   [clojure.run.exec$requiring_resolve_SINGLEQUOTE_
    invoke
    "exec.clj"
    29]
   [clojure.run.exec$exec$fn__165 invoke "exec.clj" 83]
   [clojure.run.exec$exec invokeStatic "exec.clj" 82]
   [clojure.run.exec$exec invoke "exec.clj" 78]
   [clojure.run.exec$_main$fn__220 invoke "exec.clj" 228]
   [clojure.run.exec$_main invokeStatic "exec.clj" 224]
   [clojure.run.exec$_main doInvoke "exec.clj" 192]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [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
  "Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.",
  :phase :execution}}

What does cd hello-world && clojure -Stree display?

% cd hello-world && clojure -Stree
org.clojure/clojure 1.11.1
  . org.clojure/spec.alpha 0.3.218
  . org.clojure/core.specs.alpha 0.2.62
clojure.java-time/clojure.java-time 0.3.2
  . clj-tuple/clj-tuple 0.2.2
time-lib/time-lib /home/pradmin/ocs/esign/prg/clj/depscliguide2/time-lib
  X clojure.java-time/clojure.java-time 1.2.0 :use-top

there is java-time 0.3.2 as well as 1.2.0 in ~/.m2
however, they aren’t showing up the same way.

i thought i should get a
clojure.java-time/clojure.java-time 1.2.0
instead of
X clojure.java-time/clojure.java-time 1.2.0 :use-top
(not that i know what it all means, anyway, yet.)

Do you have :deps in your user-level deps.edn file with that old clojure.java-time dependency in it?

yes!!
i commented it out and it works!
i changed it to 1.2.0 and it works!

so the system is getting confused?
or is it defaulting to the java-time 0.3.2 in ~/.clojure/deps.edn
but being asked to go to the time-lib/src/hello-time.clj which tries to send it to the 1.2.0?

that must be the crucial conundrum, because when we run hello.clj from time-lib, there is no problem.

so if an ns asks to use a library ‘indirectly’ by referencing another library which references the item, we must not have a different version at the top level.

is this reasoning correct?

thx very much too for helping me with this, sean!!

Unless you specify -Srepro, your user-level deps.edn will apply in every project – and any :deps in there will be applied as top-level dependencies everywhere, which will override any transient versions of those dependencies.

You shouldn’t use :deps in the user deps.edn – put things under aliases so you can specify those things as needed.

See dot-clojure/deps.edn at develop · seancorfield/dot-clojure · GitHub for my user deps.edn as an example.

ok!!
:deps are gone!

i will learn more about the deps.edn file now that i’ve seen yours.

thx for once again furthering my understanding!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.