So thanks to all the responses to my previous question : Starting a new ClojureScript project in 2022. Setup suggestions
It’s been very useful and informative. And I’m truly grateful.
But I’m continuing here because I think this experience, and the frustrations, are important for the community to think about.
I’m certainly no Clojure expert. (This is really bringing this home to me). But I have been using Clojure happily in my projects since 2014. I’m kind of surprised I’m having so much trouble with this now.
The key is that I’ve previously been using Lein to make my projects. And that has “just worked”. The one time I made a project with CLI tools I used GitHub - oakes/Lightmod: An all-in-one tool for full stack Clojure And that was fine too. But AFAICT that is more or less abandoned / not being updated. Plus it brings a lot of dependencies I don’t need, and none of the templates it comes with are quite what I want. It’s a shame because it was very useful.
So now I want to be able to start new projects in a “proper” and up-to-date way. The way I’m “meant” to do it. But it’s hard, partly because new things seem to be being invented all the time, and old things seem to be going out of date. And you have no idea whether random tutorials online are still relevant or broken.
So. What I want to do is setup a simple ClojureScript + Reagent + Figwheel project with tools.build / tools.deps so that I can incorporate a library which I am developing in parallel in a separate project.
What I want to do is the equivalent of
lein new reagent myproj +figwheel
as described on GitHub - reagent-project/reagent-template: A Leiningen template for projects using Reagent.
In fact, I know this is EXACTLY what I want to do, because right now, that’s what I’m doing. I’ve been able to set my project up like this and have started working on it.
But I STILL don’t know how to do the equivalent with CLI / tools.deps. And still can’t find an equivalently straightforward and comprehensive example online.
As I say, the only reason I don’t use Lein for this is because I want to pull from another development project on my machine. Which AFAICT Lein still can’t do. (If someone tells me Lein CAN now do this, I’ll stop worrying and just use Lein in a heartbeat)
But given that I can’t do that, I need to get to grips with CLI / tools.deps
So, of course. What I tried was @seancorfield’s GitHub - seancorfield/clj-new: Generate new projects based on clj, Boot, or Leiningen Templates!
clojure -Tclj-new create :template reagent :name myname/newproj
That, AFAICT is something that takes the Lein template and makes a tools.dep project from it, right?
Fine. It runs, I go into the directory. All I have to do is edit the deps.edn to add my new dependencies and …
Ah, so where’s the deps.edn file?
There isn’t one. I thought this was adapting the lein template to tools.deps? OK. Maybe not that straightforward.
Well let’s at least try to run the thing.
clj -X newproj/run
(based on Clojure - Deps and CLI Guide )
Namespace could not be loaded: newproj
OK. I should really go and read Sean’s page. So let’s try
clojure -M -m myname.newproj
Based on what he says there.
Hmmm …
Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate newproj__init.class, newproj.clj or newproj.cljc on classpath.
Full report at:
/tmp/clojure-2441616383675739567.edn
Shall we go and look in /tmp/clojure-2441616383675739567.edn ? I won’t bore you with the details. It’s just a variant on not being able to find any file it thinks is an executable entry point.
So this directory doesn’t have a deps.edn file, but it DOES still have a project.clj file for lein.
So can lein run it?
lein figwheel
Well … starts promising. Until I hit the
Exception in thread "Thread-10" java.lang.NullPointerException
at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
at java.base/java.util.regex.Pattern.matcher(Pattern.java:1133)
at clojure.core$re_matcher.invokeStatic(core.clj:4881)
at clojure.core$re_find.invokeStatic(core.clj:4923)
at clojure.core$re_find.invoke(core.clj:4923)
at cljs.analyzer$analyze_file.invokeStatic(analyzer.cljc:4850)
at cljs.analyzer$analyze_file.invoke(analyzer.cljc:4826)
at cljs.analyzer$analyze_file.invokeStatic(analyzer.cljc:4840)
at cljs.analyzer$analyze_file.invoke(analyzer.cljc:4826)
at cljs.analyzer$analyze_file.invokeStatic(analyzer.cljc:4836)
at cljs.analyzer$analyze_file.invoke(analyzer.cljc:4826)
at cljs.repl$repl_STAR_$fn__8064$fn__8065$fn__8068.invoke(repl.cljc:1181)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:671)
at clojure.core$bound_fn_STAR_$fn__5818.doInvoke(core.clj:2020)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.lang.Thread.run(Thread.java:829)
ClojureScript 1.11.54
Now, to be fair, this is probably not tools.dep nor Sean’s fault. There just must be something a bit weird / wrong with this template.
Though the lein project created with the same template works fine. So it’s not the template by itself that’s broken. But some mismatch between the template and the CLI environment?
Or maybe clj-new has done a perfectly good job of adapting the lein template, and this is a fully working project.
I just don’t have the faintest idea how the devil I’m meant to run it! Nor where I can find that information
Perhaps I’m getting this backwards. And it’s really about figwheel. This is a figwheel project after all, so how do I run that with CLI? Quick Google turns up figwheel-main | Figwheel Main provides tooling for developing ClojureScript applications which suggests I run
clj -M -m figwheel.main
Nah …
Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate figwheel/main__init.class, figwheel/main.clj or figwheel/main.cljc on classpath.
Full report at:
/tmp/clojure-15651618584841800008.edn
Well of course it doesn’t run. It probably needs a deps.edn file to tell it where to find the entry point to the app.
But that’s exactly what clj-new didn’t produce.
So I’m concluding that clj-new to adapt / convert the lein template is a non-starter. After all where would I add my dependencies without a deps.edn file?
And if anyone does know a magic formula for CLI tools.dep that does the same as
lein new reagent myproj +figwheel
then I’d be very grateful. Otherwise I’m off back to google to explore some other options.
cheers …