Should the -M
flag for Clojure CLI tools have an issue when also supplying -Sdeps
options? (the -A
flag works without issue for the same command)
/usr/local/bin/clojure -M:env/test -Sdeps '{:deps {}}'
This gives an error, whether or not the :deps
contains any dependencies.
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-Sdeps (No such file or directory)
I first experienced this issue when running Clojure CLI tools with Cider (Emacs) and using the -M flag, specifically with cider-jack-in which injects the relevant dependencies for cider-nrepl using `-Sdeps argument. I can disable the actual dependencies, but not yet
Testing the same command on the terminal, gives the same error.
Using the command without the -M:env/test
alias, only the -deps
arguments works
Using the -A
flag works with S-deps
argument
Starting a repl with that command, minus the -Sdeps
argument works via the command line and I can connect
I have tried this with several versions of Clojure CLI tools installed, from 1.10.1.697 onwards, including the latest pre-release. All seem to have the same issue.@jr0cket The -S...
options should go before -M
clj-opts before exec-opts (although they are mentioned in the other order in the help text, that order is documented as Run main clojure [clj-opt*] -M[:aliases] [init-opt*] [main-opt] [arg*]
)
(I've made the same mistake before)
Yes, putting the -M after -Sdeps does seem to work on the terminal.
That ordering is not the case with -A
flag and so sounds like a change is required for Cider to work correctly with jack-in. The ordering can be changed by editing the the command line each time, but using .dir-locals.el
config to set the alias, the -M
and -A
flags are put before the -Sdeps
option
I assume -A
will also work after -Sdeps
option, to support those who havent upgraded to Clojure CLI tools
the same rules apply for -A
Start a REPL clj [clj-opt*] [-A:aliases] [init-opt*]
Except -A
doesnt uphold that rule in practice...
It's a case of Hyrum's law, but I guess the tools doing it wrong should be changed.
Confirmed that editing the cider command line and putting -M
flag in the correct place does work :)
/usr/local/bin/clojure -Sdeps '{:deps {nrepl {:mvn/version "0.8.2"} refactor-nrepl {:mvn/version "2.5.0"} cider/cider-nrepl {:mvn/version "0.25.3"}}}' -M:env/test -m nrepl.cmdline --middleware '["refactor-nrepl.middleware/wrap-refactor", "cider.nrepl/cider-middleware"]'
I'll raise an issue with Cider to see if they can fix this. Thanks.That's annoying. It looks like we'll need to write a parser for the arguments or something and split on it? Not too terrible, but it is if you want to be backwards compatible.
@dominicm I just submitted an issue for this on the cider repository https://github.com/clojure-emacs/cider/issues/2916
And there is a pull request that fixes this issue https://github.com/clojure-emacs/cider/pull/2917
Hmm, I guess I'll have to check if my scripts use prefix or suffix form. That pattern is used in other tools too.
or just don't use cider-jack-in. I never use it.
I do. It's a useful tool, especially for beginners. Having less pieces to understand is very useful.
Having less magic to understand is also useful ;)
I also really like that CIDER can start up almost any project for you automatically without thought. It displays its startup command in the repl so you know there actually isnβt any magic. Itβs just an extra dep and a main so you can run from the clj easily
There's no magic, just trying to build on top of simple tools underneath. It's more like an abstraction.
It feels like too much magic to me. Also I don't want the REPL to be a subprocess of my editor..
the subprocess part is fair π If there's a problem in your lisp interpreter from 1970 your repl goes down ...
Clojure tools (clj) https://clojure.org/releases/tools#v1.10.1.727 is now available: β’ Fix clj -X:deps tree adding tools.deps.alpha to tree β’ Fix clj -X:deps mvn-pom adding tools.deps.alpha to pom deps β’ Fix clj -X:deps git-resolve-tags not working β’ https://clojure.atlassian.net/browse/TDEPS-152 - Fix clj -X:deps mvn-install on jar to also install embedded pom β’ Fix clj -Spom not respecting dep modifications from -A (regression)
Is there any way to install dependencies from a given alias without running an associated :main-opts
in the alias? Essentially I want a -e ""
that ignores the main-opts
(specifically from the CLI, I realize its very doable via the clj package)
implementation detail, subproc part could change :)
Right now my best shot is using babashka to construct a new deps.edn
and invoking clj -Sdeps
clj -Sdeps "`cat deps.edn | bb -I -e "{:deps (merge (:deps (first *input*)) (get-in (first *input*) [:aliases :native-image :extra-deps]))}"`" -e ""
But this feels like quite the hack@rschmukler (I don't think you need -I here, since you're reading only one EDN value)
cat deps.edn | bb -e "{:deps (merge (:deps *input*) (get-in *input* [:aliases :native-image :extra-deps]))}"
Right on! I misunderstood the CLI. I thought -I
coerced to EDN from string literal
-I is for reading multiple EDN values from stdin
The official way is to use the -P
option: https://clojure.org/reference/deps_and_cli#_prepare_for_execution
So clojure -P -M:my:aliases:here
assuming you're using a recent release of the CLI.
@seancorfield perfection! Sorry that I missed that. Might be worth adding that to the clj --help
docs too
It's in that help
exec-opts:
-A:aliases Use aliases to modify classpath
-X[:aliases] Use aliases to modify classpath or supply exec fn/args
-M[:aliases] Use aliases to modify classpath or supply main opts
-P Prepare deps - download libs, cache classpath, but don't exec
Then clearly my clj must be outdated lol!
Right'o - thank you for the help!
(! 652)-> clojure -Sdescribe
{:version "1.10.1.727"
:config-files ["/usr/local/Cellar/clojure@1.10.1.727/1.10.1.727/deps.edn" "/Users/sean/.clojure/deps.edn" "deps.edn" ]
:config-user "/Users/sean/.clojure/deps.edn"
:config-project "deps.edn"
:install-dir "/usr/local/Cellar/clojure@1.10.1.727/1.10.1.727"
:config-dir "/Users/sean/.clojure"
:cache-dir ".cpcache"
:force false
:repro false
:main-aliases ""
:repl-aliases ""}
:version "1.10.1.645
There we are
Yeah, 645 was one of the prerelease builds while a lot was changing in the CLI.
Now I've just gotta figure out why Manjaro hasn't kept up
Updated my clojure and sure enough, it's all there for me. Thanks again @seancorfield
Clojure CLI 1.10.1.697 is the minimum version for the -P
and new mode for the -M
flags. 1.10.1.727 is the latest (officially release today)
https://clojure.org/releases/tools for your version questions
I'll be glad when -A
changes to no longer run :main-opts
π
I did a little cheat sheet of command line flags to help me remember https://github.com/practicalli/clojure-deps-edn#clojure-cli-main-flag-options
Thanks for the review, those issues are now fixed, along with further explanation.
Using a :project/run
alias seems to make most sense as a project level deps.edn, so the specific namespace and function names are in the config. I'm adding this to the templates I'm creating with clj-new.
@alexmiller This is still the plan, at some point, right?
yes
I expect that to be ~months
When I run clj
i get an exception about building the class path. I tried deleting my cpcache. If you can think of something else i can try please chime in.
gist file is my deps.edn. the comment contains the command run and output (error): https://gist.github.com/drewverlee/893a150c780a86fbf73cd789b48d9b40
Thanks in advance. ill post in this thread if i figure it out.
#:com.datomic{ion-dev #:mvn{:version "0.9.276"}}
the ion-dev
does not begin with a colon but in #:mvn{:version
it does. can you try fixing that?
scratch that. namespaced symbols look strange to me in that fashion π
@jr0cket I see
Run the project clojure -X:project/run -m domain.main-namespace
but there's no :project/run
alias in your deps.edn
so I'm not sure what this is meant to do? (and it seems weird to have -X
and then have -m domain.main-namespace
as well?)It is strange, I'll clean it up. But I'm guessing that's not it. That's from copy pasting
Also, you have
Package library clojure -X:project/jars
That should be -X:project/jar
singular, yes?I don't think that's it - this look like maybe a bad version range in some transitive dep?
although I know all those deps so not sure what you'd find there :)
{:deps #:com.datomic{ion-dev #:mvn{:version "0.9.276"}}
under an alias, that should be :extra-deps
, not :deps
(or :override-deps
)typo: mvn/verison
Ah yes, on com.datomic/ion {:mvn/verison "0.9.48"}
newest version of clj will give you a better error message there