Search code examples
clojuredependencieslibraries

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]]
]

Solution

  • 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]