tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
Shantanu Kumar 2021-06-27T09:32:22.385700Z

Hi. I'm looking for a sample project/repo that maintains both project.clj and deps.edn - some way to specify the dependencies in just one place. Would appreciate any pointers.

Shantanu Kumar 2021-06-27T09:43:03.385800Z

I've found https://github.com/RickMoynihan/lein-tools-deps

borkdude 2021-06-27T10:00:24.386100Z

It's fairly easy to keep a list of deps in an edn file and then generate the project.clj and deps.edn from a template, but this will limit you to non-git-deps

borkdude 2021-06-27T10:01:07.386300Z

or just keep the deps.edn as the source of truth (since it's already just edn) and then generate the project.clj from that (using a template)

mpenet 2021-06-27T10:14:02.386600Z

I used to do that, it's brittle. Dependency resolution is different between the two, so you might end up in weird situations if you use stg like pedantic.

borkdude 2021-06-27T10:24:03.386900Z

Perhaps lein could one day use tools deps alpha as the resolution mechanism?

🙏 1
borkdude 2021-06-27T10:24:29.387100Z

at least optionally

seancorfield 2021-06-27T17:40:49.388600Z

@kumarshantanu It's definitely an approach that has problems so I would ask why you want to do this? Rick's repo README does a great job of talking about the potential problems (due to the inherent mismatch between how lein and t.d.a handle dependency resolution) and the downsides of the trade off he makes. I created a similar tool for boot (prior to Rick's lein plugin, I believe) because we were using Boot but already had our dependencies external (in deps.edn -- albeit a different format at first). Here's mine https://github.com/seancorfield/boot-tools-deps -- again, the README talks about limitations and differences and I decided to archive the repo and discourage its use, because it was just too hard to make it work properly beyond the simplest cases! At work, we decided it was simpler to switch completely to the CLI and deps.edn and abandon trying to integrate the two approaches (we'd already switched from lein to boot years earlier for the flexibility Boot provided over Leiningen).

seancorfield 2021-06-27T17:41:29.388900Z

My advice would be to just switch from lein to t.d.a/CLI deps.edn and avoid trying to integrate them. Or stay with lein and ignore deps.edn for now.

Shantanu Kumar 2021-06-27T18:51:18.389200Z

Thanks, @seancorfield I was trying to keep the benefits of both and the freedom (for developers) to choose either, but as you and others have mentioned, it's nondeterministic and error prone.

borkdude 2021-06-27T18:52:54.389400Z

I do have a deps.edn and project.clj for a lot of open source projects, exactly for that reason and I never had any conflicts there, probably because libraries tend to have fewer deps

seancorfield 2021-06-27T18:57:35.389700Z

@borkdude I'm curious about what benefits you perceive for a library project to have both? (assuming the deps.edn/CLI side can do "everything" that the Leiningen side can)

seancorfield 2021-06-27T18:59:11.389900Z

(there are definite benefits -- for CLI users -- to have even a minimal deps.edn added to a Leiningen project, so that it can participate as a :git/url dep, but I don't see much benefit in having project.clj added to a deps.edn project if your dev/test/build setup is based on the CLI)

borkdude 2021-06-27T18:59:25.390100Z

As I just explained to @ericdallo :

👍 1
borkdude 2021-06-27T18:59:49.390500Z

also I want to be flexible for other maintainers

seancorfield 2021-06-27T19:00:08.390700Z

@kumarshantanu I think there's value in forcing "encouraging" Leiningen users to install the CLI and start learning deps.edn since it's the "official" tooling -- and we have tools.build on the horizon as well 🙂

seancorfield 2021-06-27T19:06:09.391Z

@borkdude Fair enough. I'm looking forward to clojure -X:build test jar deploy as a CI process. We're not quite there yet, but I think that will beat what Leiningen offers. At work we just replaced our long build shell script with build.clj as a stepping stone toward tools.build, and the next version of depstar will offer the option of running pom, aot, and jar/`uberjar` as separate tasks, along with offering a :target-dir option.

borkdude 2021-06-27T19:07:12.391200Z

what's the syntax again for the -> semantics vs. providing key/vals?

seancorfield 2021-06-27T19:13:40.391400Z

clojure -X:aliases func1 func2 func3 :some '"arg"' :and '[:more :stuff]' = (-> {:some "arg", :and [:more :stuff]} (func1) (func2) (func3)) -- you mean that?

seancorfield 2021-06-27T19:14:03.391600Z

(plus any :exec-args from the :aliases obvs)

borkdude 2021-06-27T19:14:28.391800Z

what if you want to pass func1 func2 as a key value pair?

borkdude 2021-06-27T19:14:46.392Z

the keys have to start with a colon?

seancorfield 2021-06-27T19:15:34.392200Z

You can always pass a hash map at the end: '{func1 func2}' -- just bear in mind those are then passed as symbols.

seancorfield 2021-06-27T19:16:49.392400Z

clojure -X:aliases func1 '{func2 func3, :some "arg", :and [:more :stuff]}' -- like so (assuming you meant passing func2 func3 not func1 func2?)

seancorfield 2021-06-27T19:19:24.392700Z

or clojure -X:aliases func1 :some '"arg"' :and '[:more :stuff]' '{func2 func3}' if you wanted to combine named args and a hash map. Just like Clojure 1.11 calls 🙂

borkdude 2021-06-27T19:21:44.392900Z

ah right, trailing maps