Back

add-lib (clj)

(source)

function

(add-lib lib coord) (add-lib lib)
Given a lib that is not yet on the repl classpath, make it available by downloading the library if necessary and adding it to the classloader. Libs already on the classpath are not updated. Requires a valid parent DynamicClassLoader. lib - symbol identifying a library, for Maven: groupId/artifactId coord - optional map of location information specific to the procurer, or latest if not supplied Returns coll of libs loaded, including transitive (or nil if none). For info on libs, coords, and versions, see: https://clojure.org/reference/deps_and_cli

Examples

clojure
(ns clojure.test-clojure.repl.deps
  (:use clojure.test)
  (:require [clojure.string :as str]
            [clojure.repl.deps :as deps]
            [clojure.main :as main]))

;(deftest test-no-add-libs-outside-repl
;  (try
;    (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})
;    (is false "add-libs outside repl should throw")
;    (catch Throwable t (str/includes? (ex-message t) "add-libs")))
;
;  (with-dynamic-loader
;    (binding [*repl* true]
;      (is (some #{'org.clojure/data.json} (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})))))
;  )
clojure/clojure
(ns clojure.test-clojure.repl.deps
  (:use clojure.test)
  (:require [clojure.string :as str]
            [clojure.repl.deps :as deps]
            [clojure.main :as main]))

;(deftest test-no-add-libs-outside-repl
;  (try
;    (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})
;    (is false "add-libs outside repl should throw")
;    (catch Throwable t (str/includes? (ex-message t) "add-libs")))
;
;  (with-dynamic-loader
;    (binding [*repl* true]
;      (is (some #{'org.clojure/data.json} (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})))))
;  )