This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-11
Channels
- # adventofcode (52)
- # announcements (3)
- # aws (2)
- # babashka (36)
- # babashka-sci-dev (4)
- # beginners (69)
- # biff (45)
- # calva (9)
- # cider (3)
- # clara (8)
- # clj-kondo (24)
- # clojure (20)
- # clojure-dev (12)
- # clojure-europe (12)
- # clojurescript (2)
- # conjure (1)
- # emacs (17)
- # lsp (69)
- # malli (12)
- # off-topic (32)
- # polylith (2)
- # re-frame (4)
- # releases (2)
- # scittle (6)
- # shadow-cljs (21)
- # tools-deps (10)
- # vim (11)
- # xtdb (11)
I was reading this piece of documentation: https://clojure.org/reference/deps_and_cli#_dependencies
What I want is to have something similar to Leiningen's profiles where I could have test dependencies separate from production dependencies.
I think this should be achieved by :aliases
as I didn't find more places where I could put additional dependencies in.
So now I can't understand how to merge two :aliases
together. For instance in Leiningen I could have my dev
profile where I could declare dev dependencies (something the REPL would run against). Then I could include that profile into test
profile so that the tests would include both lists of extra dependencies.
This is an excerpt from my project.clj
file:
:profiles {:dev [:project/dev :profiles/dev]
:test [:project/dev :project/test :profiles/test]
:project/dev { ;; extra deps, extra JVM opts etc
When I run lein test
I get all dependencies from :project/dev
.
Is there a way to achieve the same in tools.deps?
Can :aliases
be used the same way as :profiles
in Leiningen? How could I do it without respecifying the same list of dependencies?In simple terms, the top level :deps
and :path
keys in a deps.edn
file represent production (and every other environment). The are always included by default (unless explicitly removed by an alias or using the -T
exec option)
So all aliases could be viewed as very flexible, on the fly leiningen profiles, although its not usually a 1-2-1 mapping.
Aliases are only used when they are included in the clojure
command line, e.g. clojure -M:env/dev:repl/rebel
which has two aliases chained together. Aliases merge with the :deps
and :path
top level keys (and the configuration from the clojure install which adds src
as a path and inlcudes org.clojure/clojure
as a dependency
In the above example I included two aliases
• :env/dev
for an extra-path to include dev
directory on the class path and any libraries I only use during development
• repl/rebel
to include library dependencies to run Rebel Readline rich terminal UI and to define the main-opts that run nrepl and the rebel code (rather than running the built-in repl prompt)
Or something like clojure -M:env/test:test/run
could be used to set the test environment and libraries and start a test runner.
There are some example of how I use aliases at https://practical.li/clojure/clojure-cli/install/community-tools-available.html
There are many examples of aliases I use in my user level configuration https://github.com/practicalli/clojure-deps-edn
Oh so I don't need to do clojure -A:test:dev -M:nrepl
?
And instead I can just do clojure -M:test:dev:nrepl
?
Oh wow, your config is really overwhelming. But yes, I can now try to make something out of it.
Thanks, I think I managed to make it work.
Yes, clojure -M:test:dev:nrepl
is what I would recommend. Note that if using :main-opts
key in any of the aliases, only the :main-opt
from the alias in the chain is called, so only one thing is 'run'.
More details about aliases can be found in this article https://practical.li/blog/posts/clojure-cli-tools-understanding-aliases/ which may be simpler than poring though my deps.edn file 🙂
> one thing is 'run'.
The last one from the :
list?
I made separate configs for dev
, test
, clj-test
, babashka-test
and nrepl
. And out of those only the last three will have -m
options. This way I could combine dev
and test
in any way.
I also used bb.edn
file to run everything using babashka. This way I don't need to remember any of the commands and they can be more complicated.
Yes, aliases all start with :
as they are keywords, so the last alias name in the chain of aliases. So your aliases are :dev
, :test
, etc...
-M
is the alias option that runs :main-opts
with clojure.main (`-X` and -T
use clojure.exec instead of clojure.main)
-m
is an option that sets the main namespace (-m can also be used in :main-opts
) and a main namespace is required for clojure.main
Is there a way to see whether a dependency from git sources was downloaded to somewhere? I created a private repository and the REPL says that it downloads it but I can't seem to use it in the code :thinking_face: I want to investigate whether my namespace names are correct but I'm not sure how to do it.
The downloaded source project is based on tools.deps
too.
This is the output from my project where I used the source project as a dependency:
Checking out: :___/___.git at 98433____0445
It seems that it should've worked but where can I find the files then?
It creates .cpcache
directory. Is this it?
I also tried to move my sources to src/...
and to src/clojure/...
but neither seem to be working :thinking_face:Found it, it's under ~/.gitlibs/libs
.