jrahme
jrahme

Reputation: 263

Specify version of library to use when other libraries use different versions in clojure

Right now I am working on a clojure project which has other code that has been written in house. Through all this code one of our libaries has been implemented several times, I know in my project.clj file I can specify to not pull in that library with something like

:dependencies[
    [my-library "2.1.1" :exclusions [old-lib]]
    [their-library "2.1.3" :exclusions [old-lib]]
    [new-library "0.0.1"]
]

Is there a way for me to specify to use the version of old lib in new-library as opposed to specifying all the places not to use it? So rather than saying exclude everywhere, just specify to use new-library's version of old-lib. Something like ...

:dependencies[
    [my-library "2.1.1"]
    [their-library "2.1.3"]
    [new-library "0.0.1" :use-this-lib [old-lib]]
]

Upvotes: 2

Views: 717

Answers (2)

Yonathan W'Gebriel
Yonathan W'Gebriel

Reputation: 1048

Another option is to use :managed-dependecies. It will let you specify a "fall-back" version for a dependency that leiningen encounters at multiple places. Move such dependencies to the :managed-dependencies block, then specify them again in the :dependencies block without a version.

:managed-dependencies [
  [old-lib "DESIRED-VERSION"]]

:dependencies[
  [old-lib]
  [my-library "2.1.1"]
  [their-library "2.1.3"]
  [new-library "0.0.1"]]

This page explains the concept well. https://cljdoc.org/d/leiningen/leiningen/2.9.5/doc/managed-dependencies-with-leiningen

Upvotes: 0

Kyle
Kyle

Reputation: 22258

Leiningen has a global :exclusions key you can use to exclude from all dependencies and provide the dependency yourself.

https://github.com/technomancy/leiningen/blob/ee57b19a5daae0687f22c7aba0da55538366664f/sample.project.clj#L63-L66

:dependencies[
  [my-library "2.1.1"]
  [their-library "2.1.3"]
  [new-lib "0.0.1"]
]
:exclusions [old-lib]

Upvotes: 1

Related Questions