Share your thoughts in the 2025 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in tools.deps by

I want to access an aar/zip artifact in build.clj that's already downloaded via deps.edn:

{:deps
 {com.newrelic.agent.android/android-agent {:local/root "build/jars/android-agent.jar"
                                            :doc        "extracted from aar"}
  com.newrelic.agent.java/newrelic-api     {:local/root "build/jars/newrelic-api.jar"
                                            :doc        "extracted from newrelic-java.zip"}}
 :aliases
 {:build {:deps       {io.github.clojure/tools.build            {:mvn/version "0.10.11"}
                       com.newrelic.agent.java/newrelic-java    {:mvn/version "8.25.1"
                                                                 :extension   "zip"}
                       com.newrelic.agent.android/android-agent {:mvn/version "7.6.14"
                                                                 :extension   "aar"}}
          :ns-default build}}}

In build.clj I need to unpack this zip and extract a jar from it.
And I don't have to hardcode .m2 paths or duplicate the version.

How can it be done?

See https://github.com/clojure/tools.deps/blob/46661e929ab702d0ee532188edb58d06b39cef6c/src/main/clojure/clojure/tools/deps/extensions/maven.clj#L172

1 Answer

0 votes
ago by

In tools.build you can find these paths in the :libs key of the basis when you build it, so that would give you the path.

You can then use unzip in the tools.build api to help unzipping it. See https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-unzip

ago by
I get empty paths:

deps.edn

  {:aliases
   {:artifacts {:deps {com.newrelic.agent.java/newrelic-java {:mvn/version "8.25.1"
                                                              :extension   "zip"}}}
    :build     {:deps       {io.github.clojure/tools.build {:mvn/version "0.10.11"}}
                :ns-default build}}}

build.clj

  (ns build
    (:require
     [clojure.tools.build.api :as b]
     [clojure.pprint :as pp]))

  (def build-basis (b/create-basis {:aliases [:artifacts]}))

  (defn prepare [_]
    (-> build-basis
        #_:libs
        #_(get 'com.newrelic.agent.java/newrelic-java)
        (pp/pprint)))


;; -> basis -:libs
  com.newrelic.agent.java/newrelic-java
  {:mvn/version "8.25.1",
   :extension "zip",
   :deps/manifest :mvn,
   :parents #{[]},
   :paths nil},
...