tools-deps

2023-09-09T06:26:48.568349Z

Is it possible to add a dependency from the command line and invoke -X with an alias at the same time? I have the following invocation (generalized):

clojure -Sdeps '{:deps {com.github.markbastian/myproject
                  {:git/url ""
                  :sha     "SOMEGITSHA"}}}' \
                   -X:myalias myproject.main/run
When I run the command, I get the message: WARNING: Specified aliases are undeclared and are not being used: [:myalias]. How might I do this? I can invoke clj -X:myalias myproject.main/run from within the project just fine. The alias is definitely in the deps edn associated with the sha of the commit.

dpsutton 2023-09-09T11:47:31.527349Z

i think because you are clobbering the deps.

❯ cat deps.edn
{:deps {}
 :aliases
 {:demo {:exec-fn clojure.core/println}}}
❯ clj -Sdeps '{:aliases {:crit {:extra-deps {criterium/criterium {:mvn/version "LATEST"}}}}}' -X:crit:demo :a 1
{:a 1}

dpsutton 2023-09-09T11:47:43.414889Z

put the extra stuff in an alias

dpsutton 2023-09-09T11:50:59.917339Z

actually, it seems fine in your original case for me:

# a dep in the deps.edn file
❯ cat deps.edn
{:deps {com.github.seancorfield/honeysql {:mvn/version "2.4.1066"}}
 :aliases
 {:demo {:exec-fn clojure.core/println}}}

# check the classpath and both are there
❯ clj -Sdeps '{:deps {criterium/criterium {:mvn/version "LATEST"}}}' -Spath
src:/Users/dan/.m2/repository/com/github/seancorfield/honeysql/2.4.1066/honeysql-2.4.1066.jar:/Users/dan/.m2/repository/criterium/criterium/0.4.6/criterium-0.4.6.jar:/Users/dan/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:/Users/dan/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar:/Users/dan/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar

# can run the exec fn with the `demo` alias
❯ clj -Sdeps '{:deps {criterium/criterium {:mvn/version "LATEST"}}}' -X:demo :a 1
{:a 1}

dpsutton 2023-09-09T13:28:02.403729Z

Oh. Are you wanting to use an alias defined in a dependency?

2023-09-09T13:29:39.286139Z

Yes, the alias is defined in myproject above.

dpsutton 2023-09-09T13:29:57.171289Z

Gotcha. I don’t believe that is supported

2023-09-09T13:30:02.673839Z

Ah, 😞

2023-09-09T13:30:38.836219Z

I can just rearrange my deps file for this.

dpsutton 2023-09-09T13:30:48.923509Z

Put an alias with the dep and exec fn info in your .clojure/deps.edn file and you can invoke it easily

dpsutton 2023-09-09T13:31:03.202609Z

No need for inline deps and such at that point

2023-09-09T13:31:44.878859Z

Cool, will do!

dpsutton 2023-09-09T13:32:03.393609Z

I imagine the reasoning is that aliases are not namespaced. So your class path could have arbitrarily many aliases with the same same

2023-09-09T13:32:28.225919Z

Makes sense, I'm sure there are a lot of :build aliases out there.

dpsutton 2023-09-09T13:33:27.492549Z

And lots of :dev. It would be cool if you could specify them with the dep name. But I suppose you’d have to be careful with which version is selected if multiple are specified by your dependency tree

2023-09-09T13:35:07.386449Z

Yeah, my thought last night (exactly what you suggested) was something like:

clojure -Sdeps '{:aliases {:my-tool {com.github.markbastian/my-app
                       {:git/url ""
                        :sha     "..."}}}}' \
                   -X:my-tool:my-alias my-app.main/run

2023-09-09T13:36:05.620089Z

But that has some ambiguity about the nested aliasing. For now I'll just do exec fn.