Fork me on GitHub

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 (
-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 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.

👍 3

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


And there is a pull request that fixes this issue


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.

😢 9

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

👍 6

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..


implementation detail, subproc part could change :)


the subprocess part is fair 🙂 If there's a problem in your lisp interpreter from 1970 your repl goes down ...

Alex Miller (Clojure team)14:10:38

Clojure tools (clj) 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 • - Fix clj -X:deps mvn-install on jar to also install embedded pom • Fix clj -Spom not respecting dep modifications from -A (regression)

bananadance 3
👀 6

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)


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


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

 -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 ""
 :config-files ["/usr/local/Cellar/[email protected]/" "/Users/sean/.clojure/deps.edn" "deps.edn" ]
 :config-user "/Users/sean/.clojure/deps.edn"
 :config-project "deps.edn"
 :install-dir "/usr/local/Cellar/[email protected]/"
 :config-dir "/Users/sean/.clojure"
 :cache-dir ".cpcache"
 :force false
 :repro false
 :main-aliases ""
 :repl-aliases ""}


:version "


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 is the minimum version for the -P and new mode for the -M flags. is the latest (officially release today)


I'll be glad when -A changes to no longer run :main-opts 🙂


@U064X3EF3 This is still the plan, at some point, right?

Alex Miller (Clojure team)18:10:10

I expect that to be ~months


I did a little cheat sheet of command line flags to help me remember


@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?)


Also, you have

Package library	clojure -X:project/jars
That should be -X:project/jar singular, yes?


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.

Drew Verlee22:10:41

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): 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 🙂

Drew Verlee22:10:25

It is strange, I'll clean it up. But I'm guessing that's not it. That's from copy pasting

Alex Miller (Clojure team)22:10:50

I don't think that's it - this look like maybe a bad version range in some transitive dep?

Alex Miller (Clojure team)22:10:16

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)


Ah yes, on com.datomic/ion {:mvn/verison "0.9.48"}

Alex Miller (Clojure team)22:10:29

newest version of clj will give you a better error message there