I’m moving from a lein project to tools deps.edn and unfortunately I had some “injections” in my project.clj
Is there a way to “inject” (i.e. require) some namespace when using the https://github.com/cognitect-labs/test-runner?
@golan1w you can use -e "(require 'foo.bar)" -m "test-runner.main"
thanks,
The problem is that when using multiple aliases only the last main-opts
in is kept. So I don’t see how can I add this to my deps.edn
to be permanent.
For example a good place for such thing would have been under alias called
:my-lib-test
create a new alias with other main opts?
yeah but then I can’t use my :runner
alias for all tests.
:runner {:extra-deps ...
:main-opts ["-m" "cognitect.test-runner"]}
and I’ll need to create a different alias for each library that needs this “injection”. This will also be a bit more complicated because I’m also building the CI integration and trying to have some code re-use.
Eventually I forkedhttps://github.com/localizedev/test-runner and added support as another command line argument…I don’t understand why deps.edn doesn’t allow to dynamically evaluate some clj expression. This quite limits the flexibility of deps.
isn't that what -M -e does?
if not, what do you mean?
I’ve a deps.edn file, I want to set the :mvn/local-repo to be :mvn/local-repo=$SOMEPATH, where $SOMEPATH is an environment variable
not possible without scripting
maybe possible with -Sdeps
Any scripting example on this subject?
I can do things like reading a template file and output a deps.edn. Just found it is a little bit unnecessary as deps doesn’t support these functionalities.
Can you accomplish this with -Sdeps
perhaps?
can you do it with stdin?
oh sorry, you're talking about in deps.edn
you can pass that particular case on the command line with -Sdeps
I think I might hack the PATH and use a wrapped verison of clj which automatically adds -Sdeps.
Eh.. A little bit complicated.
Use
@npx shadow-cljs watch mobile
shadow will invoke clojureno way to pass in -Sdeps
Anyone knows if it is possible to add -e "(require 'sc.api)"
to IntelliJ’s Run Configuration?
Is the syntax correct, btw?
I think “-e” should come before. Check out https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn
Thanks 👍
can’t you add it in an additional alias?
It seems clojure -Spom
doesn’t add :local/root
dependencies to the final pom.xml
file.
Does anyone knows if this is a known issue?
there is no way to do so?
does maven supports arbitrary path as a dependency?
the same happens with git-based dependencies
How to tell deps to ignore the deps.edn file?
You can't. deps.clj (unofficial) does support this: https://github.com/borkdude/deps.clj.
why do you want to ignore it?
A temporary fix would be -Sdeps {:deps nil}. I will use it for now.
if you have babashka installed, you can invoke it with bb clojure -Sdeps-file=other.edn
I finally go with bb to preprocess the deps.edn file. Blazingly fast.
I am writing a simple script to transform a deps.edn file, basically add some entries.
#!/bin/sh
#_stub ; -*- mode: clojure; -*-
#_(
DEPS='
{:mvn/local-repo "", :deps {}}
'
exec clojure -Sdeps "$DEPS" -M "$0" "$@"
stub)
(require '[clojure.edn :as edn])
(def deps (edn/read-string (slurp "deps.edn")))
(def newdeps (assoc deps :mvn/local-repo "../../.m2"))
(spit "deps.edn" (pr-str newdeps))
bb looks promising
This still won't ignore your local deps.edn
, it will just merge it
I don't see why that requires you to ignore the deps.edn
because this script doesn’t need to install the dependencies from deps.edn
I think you'd really want something wonkier like clj -Sdeps '{:aliases {:TMP {:replace-deps {} :replace-paths []}}}' -A:TMP
You are right.
Ideally, I would follow scope-capture’s recommendation and keep it outside the project. (https://github.com/vvvvalvalval/scope-capture)
But if that’s not possible, I could add an alias.
I tried to add it to my server
alias, which already has a :main-opts
:
:main-opts ["-m" "dvp.clj.server"]
Tried with
:main-opts ["-m" "dvp.clj.server" "-e" "(require 'sc.api)"]
but to no success.
But IntelliJ won’t even start the main function with my current alias, so maybe I need to figure out that first.I’m not sure how that even makes sense? :local/root
and :git/url
are source-only dependencies that don’t fit Maven’s group/artifact/version world — and pom.xml
doesn’t contain any information about transitive dependencies anyway.
indeed, my usage is wrong. actually this behavior makes sense. this is not a Spom problem.