Last Updated: February 25, 2016
·
664
· tomo

Lein builds classpath with a different version of a jar

When lein builds classpath with a different version of a jar than is specified in the project.clj, it's probably caused by another jar having it as a dependecy and being loaded before your code.

Example:

(defproject blah "0.1.0-SNAPSHOT"
  :description "blah"
  :url "http://www.blah.com"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [noir "1.2.2"]])

Then...

$ lein classpath
(...):~/.m2/repository/org/clojure/clojure/1.3.0/clojure-1.3.0.jar:(...)

Whaa? I want clojure 1.4.0, why lein uses 1.3.0?

Diagnosing:

$ lein deps :tree
 [noir "1.2.2"]
   (...)
   [org.clojure/clojure "1.3.0"]

Clearly, noir requires clojure 1.3.0. To fix it, you need to exclude clojure from noir dependecies:

(defproject blah "0.1.0-SNAPSHOT"
  :description "blah"
  :url "http://www.blah.com"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [noir "1.2.2" :exclusions [org.clojure/clojure]]])

And now lein does what you want.

$ lein classpath
(...):/Users/tomo/.m2/repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar:(...)