Ooberdan
Ooberdan

Reputation: 730

Can I force lein to ignore dependencies from any code external to current Clojure project?

I'm calling some Clojure (1.8) code in a larger Java project that I don't entirely have control over. Recently some code has been added to the parent that's causing conflicts with the HTTP client clj-http.

From my Clojure project, here's the output of lein deps :tree|grep http:

[clj-http "3.7.0"]    
  [org.apache.httpcomponents/httpasyncclient "4.1.3" :exclusions [[org.clojure/clojure]]] 
    [org.apache.httpcomponents/httpcore-nio "4.4.6"]    
  [org.apache.httpcomponents/httpclient "4.5.3" :exclusions [[org.clojure/clojure]]]    
  [org.apache.httpcomponents/httpcore "4.4.6" :exclusions [[org.clojure/clojure]]]    
  [org.apache.httpcomponents/httpmime "4.5.3" :exclusions [[org.clojure/clojure]]]

Running mvn dependency:tree|grep http for the other project returns the following (note that this project is also a child of the parent):

[INFO] +- org.apache.httpcomponents:httpclient:jar:4.1.1:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.1:compile

Is there a way I can ignore conflicts originating outside of my Clojure code, in lein (or otherwise)?

Upvotes: 4

Views: 1082

Answers (1)

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91534

it's necessary to slog through the conflicts and fix them. There are two approaches:

  • Exclusions: Exclude each dependency that is reported in lein deps tree from each of the upstream dependencies where it's provided. This gives you complete control when you need to make sure a transitive dependency is not included. It can though ... "be a bit of a bother" ;-)

  • Managed Dependencies: You can also add a managed-dependencies section to your project.clj where you specify the exact version of libraries that will be used, regardless of the resolution of other transitive dependencies. This is a somewhat more blunt instrurment, and one i tend to turn to.

A random example from a project:

  :managed-dependencies [[http-kit "2.3.0"]
                         [org.clojure/clojure "1.9.0"]
                         [ring/ring-core "1.6.0"]
                         [ring/ring-jetty-adapter "1.6.0"]
                         ... lots more ...]

Upvotes: 5

Related Questions