Fork me on GitHub
#clojure
<
2024-05-18
>
roklenarcic10:05:41

I had a load dependency cycle and I changed one require from :as to :as-alias and that seems to have fixed it, except when I run tests via tools build, e.g. clj -T:build ci which uses io.github.seancorfield/build-clj run-tests function. That one still reports a cycle. How is this possible? Is it running some old version of clojure?

roklenarcic11:05:41

if I run just clj and require the namespace in REPL offered, it gets loaded successfully

seancorfield16:05:33

Take build-clj out of the equation and write a simple :test alias using Cognitect's test-runner. I think you'll still get the error because the test runner loads all namespaces (and I suspect the cycle is still there, somewhere else in your code).

seancorfield16:05:37

And please stop using build-clj. It was a bad idea, and I regret creating it.

roklenarcic17:05:49

The namespaces in the cycle are clearly stated, so I don’t think there’s a cause elsewhere. I can run tests fine if I just use clj cmd and load them in the repl. It’s when I try to run test via the tools alias that the cycle magically appears. The compiler message is not factually correct. The namespaces are not in a cycle due to as-alias use.

roklenarcic17:05:25

I guess I have to create a simple reproduction.

seancorfield18:05:34

I would have expected an old version of Clojure to complain about :as-alias but apparently it doesn't -- it's just treated as :as instead 👀 TIL!

seancorfield18:05:27

(~/clojure)-(!2008)-> clj -A:1.8
Clojure 1.8.0
user=> (ns foo (:require [foo.bar :as-alias bar]))
FileNotFoundException Could not locate foo/bar__init.class or foo/bar.clj on classpath.  clojure.lang.RT.load (RT.java:456)
foo=>

Sat May 18 11:22:06
(~/clojure)-(!2008)-> clj -A:1.9
Clojure 1.9.0
user=> (ns foo (:require [foo.bar :as-alias bar]))
FileNotFoundException Could not locate foo/bar__init.class or foo/bar.clj on classpath.  clojure.lang.RT.load (RT.java:463)
foo=>

Sat May 18 11:22:14
(~/clojure)-(!2009)-> clj -A:1.10
Clojure 1.10.3
user=> (ns foo (:require [foo.bar :as-alias bar]))
Execution error (FileNotFoundException) at foo/eval138$loading (REPL:1).
Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath.
foo=>

Sat May 18 11:22:26
(~/clojure)-(!2010)-> clj -A:1.11
Clojure 1.11.3
user=> (ns foo (:require [foo.bar :as-alias bar]))
nil
foo=>
So it is possible that somehow clojure -T:build run-tests is picking up a different version of Clojure than you expect but it should be using the deps from :test -- which is what you'd get if you ran clojure -X:test directly (or clojure -M:test depending on how you have it set up)...

roklenarcic18:05:06

Interesting. Well I don’t have Clojure declared in my deps as a dependency. So I would assume that the version is used that is used by cli tools themselves. Especially considering that if I just use clj command to create repl then a fairly new version is started. I guess there might be some sort of interaction with tools alias. I do recall that with -T switch you’re starting with an empty deps list.

seancorfield18:05:52

build-clj uses clojure.tools.build.api/java-command and process to run tests in a subprocess, using the default basis for the project with the alias :test.

seancorfield18:05:58

Do you have a user-level deps.edn? Does it specify a Clojure version? And what does clojure -version show?

roklenarcic19:05:26

clojure -version
Clojure CLI version 1.11.2.1446

roklenarcic09:05:26

I have user level deps.edn but it doesn’t specify clojure version in any of the aliases