Fork me on GitHub
#tools-deps
<
2020-05-16
>
gfredericks15:05:17

can a deps.edn provide jvm-opts for default calls, without having to specify an alias?

gfredericks15:05:08

is that intentional, or a maybe-future-feature?

Alex Miller (Clojure team)15:05:50

But it seems weird that all clj invocations in a project would share those

Alex Miller (Clojure team)15:05:03

Which is why I haven’t added it yet

gfredericks15:05:37

when imagining it was intentional I started thinking that maybe for a nontrivial project clojure isn't meant to be called directly, and you'd setup bin/ scripts that call clojure with appropriate aliases

gfredericks15:05:06

at least for running specific code; maybe it's fine for launching a repl

Alex Miller (Clojure team)15:05:15

Like maybe it would make more sense if it was scoped only to running a repl

Alex Miller (Clojure team)15:05:42

Or running a specific main

gfredericks15:05:22

yeah, specific main would definitely be adequate for anything I want to do

Alex Miller (Clojure team)15:05:40

But if you’re doing that, don’t you already have an alias where you can put it?

Alex Miller (Clojure team)15:05:26

Or is it that you don’t want to repeat it in aliases

gfredericks15:05:09

hmm, you're right, I guess a human typing in a main ns might not be very common so my particular situation, which is maybe not common enough to be worth targeting, is that my "project" mostly consists of a monolithic clj file at the root, and I just run clojure code.clj a lot but I'd like to have it with a restricted -Xmx by default, and can't do that; I just have to remember to run clojure -Afoo code.clj instead

gfredericks15:05:55

I think "stop being weird" is a perfectly good answer here, I was just curious

seancorfield19:05:15

Or even just clojure -A:foo since you could add code.clj to the alias (as a :main-opts element), right?

seancorfield19:05:51

seanc@DESKTOP-QU2UJ1N:/mnt/c/Users/seanc/clojure/foo$ cat code.clj
(println "Hello from code.clj")
seanc@DESKTOP-QU2UJ1N:/mnt/c/Users/seanc/clojure/foo$ cat deps.edn
{:aliases {:foo {:main-opts ["code.clj"]}}}
seanc@DESKTOP-QU2UJ1N:/mnt/c/Users/seanc/clojure/foo$ clojure -A:foo
Hello from code.clj
seanc@DESKTOP-QU2UJ1N:/mnt/c/Users/seanc/clojure/foo$

dominicm21:05:12

If tools.deps exposed a :init-opts option in deps.edn, that would remove the need for multiple mains. Most uses (I've had) involve side-effects like launching an nrepl for personal dev purposes. If I use a main for that, I can't use a project-specific main.

seancorfield21:05:35

:main-opts can contain -e and -i -- and you can combine multiple :main-opts from multiple aliases @dominicm

seancorfield21:05:41

That's partly why I separate out :test and :runner for example.

seancorfield21:05:08

I admit, I do miss the ability of combining aliases in other aliases -- that's probably the thing that would add the most ergonomic utility for me. That's really why we have a shell script wrapped around clojure: to do some "alias expansion"

dominicm21:05:42

@seancorfield you can only have one :main-opts active from an alias at a time.

dominicm21:05:26

Compare with jvm-opts which does concatenate.

seancorfield22:05:59

Ugh! Yeah, you're right. I'd convinced myself they combine...

seancorfield22:05:29

Which means I change I made recently to my dot-clojure file doesn't actually work.

seancorfield22:05:32

(well, it does work, but not quite how I thought and it explains why I still need a manual step at the end)

seancorfield22:05:29

So, yeah, you've now convinced me that having an :init-opts for just "init opts" that actually combined like :jvm-opts would be a good thing 🙂

seancorfield22:05:58

(or, frankly, even if :main-opts itself combined and it was just "caveat programmer" to use it that way)

dominicm22:05:54

The problem with main opts composing is that there's an order problem. Not so with init-opts. I suppose people may also be relying on the fact that main-opts conflict.

seancorfield22:05:29

If you have multi -e options you might want them to execute in a particular order 🙂

seancorfield22:05:21

I added -e to my :deps alias to set up a DCL, so that if you do -A:deps:socket then you get a DCL in place before the Socket REPL is created so you able to use add-lib via Atom.

seancorfield22:05:44

But if you do -A:deps:socket:rebl-11 you get a REBL window without DCL 😞

seancorfield22:05:11

So you have to do -A:deps:socket -R:rebl-11 -r (omitting the :main-opts from REBL) and that sets up a DCL and starts a Socket REPL and finally starts a command-line REPL... and in there you can do ((requiring-resolve 'cognitect.rebl/ui)) to start the REBL window and then it does have a DCL.

seancorfield22:05:28

(this is all a workaround because Socket REPLs don't use DCLs by default)

dominicm22:05:10

@seancorfield my implementation of this in user space might interest you. You set properties using jvm opts, then have a main which reads those properties and runs evaluations from them.

😂 4
😱 4
Alex Miller (Clojure team)23:05:00

Early versions of clj did this :)

dominicm22:05:33

Implementation is a little strong perhaps. Idea :).

Alex Miller (Clojure team)23:05:33

Re init opts, at some point you’re programming, just write a clj and call it

seancorfield23:05:33

Well, that was why, in the end, we wrote our little dev/repl.clj script at work -- it looks at what's on the classpath and starts a Socket REPL, an nREPL Server, REBL, or a regular REPL.