tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
dominicm 2021-06-21T07:07:55.273600Z

Unclear from https://github.com/clojure/tools.deps.alpha/wiki/Tools is there a tool for tracking the licenses of dependencies in a deps.edn?

camsaul 2021-06-21T19:55:24.278100Z

Sorry if this is a another dumb question. How can I programmatically get all the paths to a transient dependency with tools.deps? Example: org.apache.httpcomponents/httpclient is a transient dependency of both clj-http/clj-http and org.clojure/tools.deps.alpha. I tried resolve-deps , thinking maybe it would return both of those paths in :parents, but it doesn't:

(defn http-client-parents [deps]
  (-> (t/resolve-deps
       {:deps      deps
        :mvn/repos {"central" {:url "<https://repo1.maven.org/maven2/>"}
                    "clojars" {:url "<https://repo.clojars.org/>"}}}
       nil)
      (get-in ['org.apache.httpcomponents/httpclient :parents])))

(http-client-parents
 '{clj-http/clj-http {:mvn/version "3.10.3"}})
;; -&gt;
#{[clj-http/clj-http] 
  [clj-http/clj-http org.apache.httpcomponents/httpmime]
  [clj-http/clj-http org.apache.httpcomponents/httpclient-cache]}

(http-client-parents
 '{org.clojure/tools.deps.alpha {:mvn/version "0.11.931"}
   clj-http/clj-http            {:mvn/version "3.10.3"}})
;; -&gt;
#{[org.clojure/tools.deps.alpha org.apache.maven.resolver/maven-resolver-transport-http]}
What's the right way to do this?

alexmiller 2021-06-21T20:40:15.278900Z

@camsaul I don't think the tools.deps api has a direct way to answer this question if I understand your question properly

alexmiller 2021-06-21T20:41:19.280Z

I think you're asking, given a set of root deps, why is a particular lib included in the expanded dep set?

camsaul 2021-06-21T20:43:16.282600Z

Sort of. If a transient dep is include in the expanded dep set I want to know all of the root deps that would have caused that dep to be included

alexmiller 2021-06-21T20:43:27.282700Z

the :parents keys are not part of the normative return of resolve-deps (that's an artifact of the expansion process)

👍 1
alexmiller 2021-06-21T20:44:14.283700Z

but there are shortcuts in the expansion process that can cause the info in the return here to be incomplete

alexmiller 2021-06-21T20:44:41.284400Z

it is probably better to derive this information from the tree expansion (the code that backs -Stree)

alexmiller 2021-06-21T20:46:18.284900Z

if you call make-tree with the lib-map that will be an actual tree structure

alexmiller 2021-06-21T20:47:26.285900Z

you should be able to find the leaves you want and trace their path back up

camsaul 2021-06-21T20:47:29.286300Z

I actually did look at make-tree and -Stree but it does the same thing. The don't include httpclient as a dependency of clj-http/clj-http

borkdude 2021-06-21T20:47:51.287100Z

-Stree can also print EDN right? you can also parse that on the command line I guess

camsaul 2021-06-21T20:49:08.287900Z

Here's an example (gist because it's a lot of output): https://gist.github.com/camsaul/4e8c3977ce3f423e7bfd090d5c816da3 org.apache.httpcomponents/httpclient only appears once

borkdude 2021-06-21T20:49:12.288200Z

clojure -X:deps tree :format :edn

alexmiller 2021-06-21T20:49:16.288300Z

you can do that, he'd ask for programmatic

alexmiller 2021-06-21T20:49:33.288700Z

sorry, I said make-tree above but that's the old tree printer code which is kind of vestigial now

alexmiller 2021-06-21T20:50:55.290200Z

the newer stuff is under clojure.tools.deps.alpha.tree/trace-&gt;tree which importantly is fed by a trace log which comes from running resolve-deps with the trace flag set to true

alexmiller 2021-06-21T20:56:20.290600Z

(require '[clojure.tools.deps.alpha :as deps] '[clojure.tools.deps.alpha.tree :as tree])
  (let [deps '{:deps      {org.clojure/tools.deps.alpha {:mvn/version "0.11.931"}
                           clj-http/clj-http            {:mvn/version "3.10.3"}}
               :mvn/repos {"central" {:url "<https://repo1.maven.org/maven2/>"}
                           "clojars" {:url "<https://repo.clojars.org/>"}}}
        libs (deps/resolve-deps deps {:trace true})
        tree (trace-&gt;tree (-&gt; libs meta :trace))]
    (clojure.pprint/pprint tree))

alexmiller 2021-06-21T20:56:57.291600Z

some sketch code to get the tree (this will give you a ton of output)

alexmiller 2021-06-21T20:58:43.293Z

the docstring for trace->tree gives you more info on the structure of the tree - basically it's a tree of map nodes keyed by lib, value is a map with a :children vector (which are more nodes)

👍 1
camsaul 2021-06-21T20:59:34.293600Z

awesome, thanks! Looks like it shows up under both top-level libs there. I can use that to build what I need

alexmiller 2021-06-21T21:00:28.294700Z

importantly, also check the :include flag! this tree includes nodes that are NOT included in the final deps (:reason tells you why)

👍 1
camsaul 2021-06-21T22:20:18.325700Z

I have one more question that I couldn't seem to find an answer for on http://ask.clojure.org. What do people with Java source files do to approximate Leiningen's :java-source-paths functionality? Of course, it's easy enough to do find java -name '*.java' | xargs javac -cp $(clojure -Spath) or whatever before running stuff, or even put that logic in an alias (e.g. clojure -X:compile-java ), but it's a nicer dev experience if I don't have to run two commands instead of one for everything I want to do. I'm less worried about that tho, and more worried about the experience for contributors and other people using our project. I don't want to have to change our local dev server instructions from something relatively simple like lein run to something hairy like clojure -X:compile-java &amp;&amp; clojure -X:dev-server . If there were a way to add custom tools.deps "extensions"https://github.com/clojure/tools.deps.alpha/tree/master/src/main/clojure/clojure/tools/deps/alpha/extensions I think I could get this working pretty easily with something like

{:deps {my-project/java-source {:com.my-company.java-source/local "/path/to/java/src"}}
But I'm guessing that sort of extension support isn't something that's likely to make it into the CLI any time soon. Other than doing something like setting up CI to compile the Java sources and publish them somewhere (e.g. by uploading it to an S3 bucket structured as a Maven repo), is there a way I can avoid requiring people to run a separate compile command before they are able to do anything else with the project?

alexmiller 2021-06-21T22:26:30.326700Z

Coming very soon

🎉 2
1
camsaul 2021-06-21T22:27:33.327300Z

Awesome, that's great to hear!