tools-build

Eugen 2021-08-30T13:59:51.013500Z

should tools.build create a basis with more than what it is in deps.edn file ? I'm trying to publish a zip file in a maven repo (data for an app) and with the given deps.edn:

{:paths ["target/data"]
 :deps {}
 :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.1.9" :git/sha "6736c83"}
                          slipset/deps-deploy {:mvn/version "0.1.5"}}
                   :ns-default build}}}
I have to nil dependencies and other parts because default values appear:
(def basis (merge (b/create-basis {:project "deps.edn"})
                  {:deps nil
                   :libs nil
                   :mvn/repos nil}))
Without the above nilification, I get this basis:
{:classpath
 {"target/data" {:path-key :paths},
  "/home/ieugen/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar" {:lib-name org.clojure/clojure},
  "/home/ieugen/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar"
  {:lib-name org.clojure/core.specs.alpha},
  "/home/ieugen/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar"
  {:lib-name org.clojure/spec.alpha}},
 :classpath-args {},
 :mvn/repos {"central" {:url ""}, "clojars" {:url ""}},
 :paths ["target/data"],
 :classpath-roots
 ["target/data"
  "/home/ieugen/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar"
  "/home/ieugen/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar"
  "/home/ieugen/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar"],
 :libs
 #:org.clojure{clojure
               {:mvn/version "1.10.3",
                :deps/manifest :mvn,
                :parents #{[]},
                :paths ["/home/ieugen/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar"]},
               spec.alpha
               {:mvn/version "0.2.194",
                :deps/manifest :mvn,
                :dependents [org.clojure/clojure],
                :parents #{[org.clojure/clojure]},
                :paths ["/home/ieugen/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar"]},
               core.specs.alpha
               {:mvn/version "0.2.56",
                :deps/manifest :mvn,
                :dependents [org.clojure/clojure],
                :parents #{[org.clojure/clojure]},
                :paths
                ["/home/ieugen/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar"]}},
 :aliases
 {:deps
  {:replace-deps
   {org.clojure/tools.deps.alpha #:mvn{:version "0.12.1003"}, org.slf4j/slf4j-nop #:mvn{:version "1.7.25"}},
   :ns-default clojure.tools.cli.api,
   :ns-aliases {help }},
  :test {:extra-paths ["test"]},
  :build
  {:deps
   {io.github.clojure/tools.build #:git{:tag "v0.1.9", :sha "6736c83"}, slipset/deps-deploy #:mvn{:version "0.1.5"}},
   :ns-default build}},
 :resolve-args {},
 :deps #:org.clojure{clojure #:mvn{:version "1.10.3"}}}
Notice filled values for :deps, :mvn/repos and :libs that I did not supply in my deps.edn file

Alex Miller (Clojure team) 2021-08-30T14:01:02.013800Z

you can choose what deps sources are included in the basis

Alex Miller (Clojure team) 2021-08-30T14:01:19.014100Z

by default, you'll get root, user, and project deps.edn

Alex Miller (Clojure team) 2021-08-30T14:02:05.014300Z

see doc at https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-create-basis

Alex Miller (Clojure team) 2021-08-30T14:02:32.014600Z

you can pass :root nil, :user nil to remove those sources

Eugen 2021-08-30T14:13:00.014800Z

thanks, that worked

Eugen 2021-08-30T14:38:26.018700Z

would it be hard to expose all options for pom creation? I'm thinking of thins like: • ability to specify a different packaging besides jar • ability to specify classifier • ability to specify a different artifact extension(for zip packages or platform specific binaries ) - not sure if this relates to packaging above.

Alex Miller (Clojure team) 2021-08-30T14:52:27.019200Z

all classifiers use the same pom so that one is not a thing

Alex Miller (Clojure team) 2021-08-30T14:52:41.019500Z

packaging can be specified in the source pom

Alex Miller (Clojure team) 2021-08-30T14:52:53.019800Z

not sure what the last one is

Alex Miller (Clojure team) 2021-08-30T14:54:09.020800Z

in general, you can set anything in a source pom that is synced - the main things replaced are deps and repos (and some of the identifier stuff), everything else comes from the source pom

Eugen 2021-08-30T20:51:24.022Z

thanks, that worked as well. I managed to upload the artifacts I wanted

👍 1
Eddie 2021-08-30T21:02:38.022300Z

Does compile-clj expand macros? I have a macro that expands differently depending on the version of one of my deps and I am wondering if AOT compilation will bind my library jars to a particular version.

Alex Miller (Clojure team) 2021-08-30T21:03:37.022900Z

by definition, macroexpansion is part of compilation, yes

Alex Miller (Clojure team) 2021-08-30T21:04:01.023500Z

and yes, that will bind your library jars to a particular version, which is why we recommend that library jars should be distributed as source

Eddie 2021-08-30T21:30:02.033900Z

Gotcha, thanks @alexmiller . I hear ya on distributing libs as source, and I would normally do that. Unfortunately, in this case my dep is scala-library (and other deps that form the Scala lang). My lib has some deftypes that implement Scala traits and require AOT compilation by either me (once before distributing the lib) or by each user individually. I'm debating how to handle this trade-off.

Eddie 2021-08-30T21:31:06.034200Z

I didn't know about the binding to the Clojure compiler. That is a very compelling argument in favor of delaying compilation as much as possible.

Alex Miller (Clojure team) 2021-08-30T21:05:42.024400Z

it also binds your artifact to whatever version of the Clojure compiler happens to be used during compilation, which may differ from the version used by an app later down the line

Alex Miller (Clojure team) 2021-08-30T21:09:08.027200Z

in practice, it can be an issue to run on an older runtime (which is controlled by the app, not your lib) than you used to compile your lib, which is again, another good reason not to distributed a compiled lib artifact

Eugen 2021-08-30T21:25:48.030700Z

is there a functionality to download dependencies to a specific folder or do I have to write my own? I could not find any while checking the deps-cli docs or deps projects list. The plan is to download the zip (s) I just uploaded and unpack them for building the docker image I need in the end. I find this to be very easy to manage via dependency management (version tracking and downloading) It worked very well in gradle for me.

seancorfield 2021-08-30T21:27:25.032700Z

You could specify the local maven repo to use (instead of ~/.m2/repository) I guess...?

Eugen 2021-08-30T21:28:59.033600Z

that might work, but to which function should I specify ? I don't know which one is responsible for downloading the deps

Eugen 2021-08-30T21:33:38.034400Z

resolve-deps seems to resolve them but I don't see the repo path option so my guess is that it's not downloading any of them

Eugen 2021-08-30T21:34:31.034600Z

Usage: (lib-location lib coord deps-config) this might also be useful

seancorfield 2021-08-30T21:36:54.034900Z

Ah, yeah, you could get the filepath after the download...

seancorfield 2021-08-30T21:38:00.035100Z

The option for which local maven cache to use is part of deps.edn so it would be part of the basis used for downloading the libs/files. Given what you're trying to do, just getting the "dependency"'s location on disk after the download is probably easier.

Eugen 2021-08-30T21:38:42.035300Z

yes, I don't need to change the repo for this

Eugen 2021-08-30T21:38:55.035500Z

do you know which function I can call to download the libs ?

Eugen 2021-08-30T21:39:15.035700Z

I could not figure it out from the API docs of https://clojure.github.io/tools.deps.alpha/

seancorfield 2021-08-30T21:39:57.035900Z

resolve-deps does it automatically behind the scenes.

Eugen 2021-08-30T21:41:08.036100Z

thanks, I'll play with that and see where it gets me

Alex Miller (Clojure team) 2021-08-30T21:53:41.036300Z

resolve-deps returns (or the basis includes) a lib map which includes the location of the libs

Alex Miller (Clojure team) 2021-08-30T21:54:38.036600Z

but setting a local-repo is a pretty quick path to this too: clj -Sdeps '{:mvn/local-repo "my/repo"}' -P

Eugen 2021-08-30T22:00:05.036900Z

thanks, Alex for the alternate solution. I got it working with

(tools/resolve-deps {:deps {'com.drevidence.docsearch/load-test-data {:mvn/version "0.1.11697"
                                                                        :extension "zip"}}
                       :mvn/repos  {"dre" {:url ""}}}
                      {:trace true}) 
it works very nice for me since I can tweek what I want.

Eugen 2021-08-30T22:12:29.037100Z

surprinzingly, lib-location does not return the file name:

(tools/lib-location 'com.drevidence.docsearch/load-test-data
                        {:mvn/version "0.1.11697"
                         :extension "zip"}
                        {:deps {'com.drevidence.docsearch/load-test-data {:mvn/version "0.1.11697"
                                                                          :extension "zip"}}
                         :mvn/repos  {"dre" {:url ""}}})
=>
{:base "/home/ieugen/.m2/repository",
 :path "com/drevidence/docsearch/load-test-data/0.1.11697",
 :classifier nil,
 :type :mvn}

seancorfield 2021-08-30T22:14:44.037400Z

@eugen.stan Does the result of resolve-deps include the full file path you want? (no need to call lib-location)

Eugen 2021-08-30T22:15:33.037600Z

yes it does - it's in a vector inside a map - grouped by group id

Eugen 2021-08-30T22:16:40.037900Z

so I'll probably use that

Eugen 2021-08-30T22:17:49.038100Z

getting back to lib-location - should it include the file name as well? I seems to me like that can be computed as well and the information returned is not complete

seancorfield 2021-08-30T22:26:08.038300Z

I hadn't even noticed lib-location -- not sure whether it's really meant to be a supported part of the API or whether it just happens to be public right now? @alexmiller?

Eugen 2021-08-30T22:30:56.038500Z

thanks for taking the time to help. going to seelp. see you tomorrow

Alex Miller (Clojure team) 2021-08-30T22:33:35.040500Z

lib-location is kind of a historical oddity at this point, I think there might be a Datomic thing still using it

Eugen 2021-08-30T21:28:07.033500Z

In gradle you could define configurations and attach different sets of dependencies to each configuration. And different parts of your programm could use the dependencies of one or another configuration. This seems to be similar to how deps.edn has :extra-deps but in gradle you can choose not to inherit from a configuration - they are pretty independent.