tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
cap10morgan 2020-12-01T18:13:10.100900Z

Is it possible / advisable to get the active deps.edn alias(es) from the Clojure code invoked by them? For example, to access app-specific settings defined in that alias?

dominicm 2020-12-01T18:14:08.101800Z

@cap10morgan look at clojure.basis system property

👍 1
dominicm 2020-12-01T18:14:21.102500Z

I think it's OK some of the time to do that, yeah.

dominicm 2020-12-01T18:14:47.103500Z

I do it to identify build directories, for example, so I can stop them being refreshed

seancorfield 2020-12-01T18:14:48.103600Z

@cap10morgan You can't tell what aliases were used to invoke your code but, as Dominic says, you can read the basis file in -- if you were started via the Clojure CLI.

👍 1
seancorfield 2020-12-01T18:15:08.104300Z

The basis is not available for code running via java -jar etc.

dominicm 2020-12-01T18:15:26.104800Z

I haven't actually looked, but I thought the active aliases were in the basis.

seancorfield 2020-12-01T18:16:14.105700Z

Yes, all merged aliases are in the basis. So you can slurp it, read the EDN, and then navigate to :aliases -> any alias.

seancorfield 2020-12-01T18:17:13.106900Z

I'm thinking it would be nice, when building an uberjar, to be able to read the basis and write it into the JAR as a resource that could be read at runtime.

dominicm 2020-12-01T18:17:18.107200Z

I mean the activated ones though. Currently rebuilding my computer so I can't check :)

seancorfield 2020-12-01T18:17:32.107600Z

Not sure what you mean by "the activated ones"?

dominicm 2020-12-01T18:17:52.108600Z

Knowing that -A:dev was called, for example

seancorfield 2020-12-01T18:18:08.108900Z

The basis is the merged deps.edn (and command-line) stuff, plus :libs and :classpath etc. No, you cannot tell what aliases were used for invocation.

cap10morgan 2020-12-01T18:29:29.109600Z

it looks like what I want is in :resolve-args of the basis. thanks!

seancorfield 2020-12-01T18:51:04.110100Z

Does that actually include the aliases used? Or just the result of processing those aliases?

seancorfield 2020-12-01T18:52:42.111Z

A quick test locally shows that :resolve-args of the basis has keys :override-deps :extra-paths :extra-deps :main-opts :jvm-opts -- so that's not the aliases, just the result of the aliases @cap10morgan

cap10morgan 2020-12-01T18:53:40.111900Z

Yeah, the result is what I want. I have app-specific keys in one or more aliases and I want to access the ones that got activated. I don't actually care which alias key(s) did it.

seancorfield 2020-12-01T18:54:14.112400Z

@cap10morgan I'm confused. What "app-specific keys" are you talking about?

cap10morgan 2020-12-01T18:55:09.113500Z

well, in general, anything you want that doesn't step on something already defined. So, for my case, I'm using :pom2project/injections.

cap10morgan 2020-12-01T18:55:30.113900Z

Alongside the :extra-deps, :main-opts, etc.

seancorfield 2020-12-01T19:01:18.114300Z

Ah, so you're outside the bounds of what deps.edn and t.d.a support there.

seancorfield 2020-12-01T19:02:06.115100Z

It just happens to work right now but I doubt that is guaranteed...

seancorfield 2020-12-01T19:06:03.115800Z

@alexmiller Can it be relied on that :resolve-args will contain any and all keys from the merged aliases selected, not just the known, supported keys?

alexmiller 2020-12-01T19:13:37.116Z

I'll say undefined :)

alexmiller 2020-12-01T19:15:01.116900Z

aliases (that are used to modify resolve-deps and make-classpath) are a feature of the clojure script, not of tools.deps or the basis

alexmiller 2020-12-01T19:16:31.118300Z

that is, they are just a mechanism with which to convey :extra-deps etc. if you look at something like calc-basis, it does not take or return anything related to aliases

alexmiller 2020-12-01T19:19:42.119700Z

if you want to read data from an alias, I would encourage you to convey the aliases to use via an argument, read the deps.edn (or calculate a basis), and extract the aliases that way. relying on stuffing extra stuff into the aliases used to make classpaths is probably not a good idea

seancorfield 2020-12-01T19:39:55.120900Z

Thanks, Alex. That's a good clarification (feature of the Clojure CLI script -- rather than t.d.a), and another reason why the "selected aliases" information is not available in the running program.

seancorfield 2020-12-01T19:40:24.121400Z

^ @cap10morgan Does that change how you feel about adding unknown keys in aliases?

cap10morgan 2020-12-01T19:52:01.122400Z

Thanks for that background. For now this approach makes the most sense for what I need so I'll probably stick with it. If I have to change it later, no big deal. Strictly for internal tooling for now.