Skip to content

Commit

Permalink
Fix global :exclusions in profile not applying to root :dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Jan 22, 2024
1 parent 82f5002 commit 34b4981
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
21 changes: 21 additions & 0 deletions leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,26 @@
(meta dependencies)))
project)))

(defn- remove-self-excluded-deps
"Remove any dependency that contains it's dependency id inside it's own
:exclusions vec."
[{:keys [dependencies] :as project}]
(if dependencies
(update project :dependencies
(fn [deps]
(when deps
(let [self-excluded? (fn [dep]
(let [{:keys [artifact-id group-id exclusions]} (dependency-map dep)]
(some (fn [{excl-art-id :artifact-id, excl-grp-id :group-id}]
(and
(= group-id excl-grp-id)
(= artifact-id excl-art-id)))
exclusions)))]
(with-meta
(remove self-excluded? deps)
(meta deps))))))
project))

(defn- absolutize [root path]
(str (if (.isAbsolute (io/file path))
path
Expand Down Expand Up @@ -960,6 +980,7 @@
(target-path-subdirs :native-path)
(absolutize-paths)
(add-global-exclusions)
(remove-self-excluded-deps)
(vary-meta merge {:without-profiles project
:included-profiles include-profiles
:excluded-profiles exclude-profiles
Expand Down
9 changes: 7 additions & 2 deletions leiningen-core/test/leiningen/core/test/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,20 @@

(deftest test-global-exclusions
(let [project {:dependencies
'[[lancet "1.0.1"]
'[[org.clojure/clojure "1.11.1"]
[lancet "1.0.1"]
[leiningen-core "2.0.0-SNAPSHOT" :exclusions [pomegranate]]
[clucy "0.2.2" :exclusions [org.clojure/clojure]]]
:exclusions '[org.clojure/clojure]}
dependencies (:dependencies (merge-profiles project [:default]))]
(is (= '[[[org.clojure/clojure]]
[[org.clojure/clojure] [pomegranate/pomegranate]]
[[org.clojure/clojure]]]
(map #(distinct (:exclusions (apply hash-map %))) dependencies)))))
(map #(distinct (:exclusions (apply hash-map %))) dependencies)))
(is (= '[[lancet/lancet "1.0.1" :exclusions ([org.clojure/clojure])]
[leiningen-core/leiningen-core "2.0.0-SNAPSHOT" :exclusions ([org.clojure/clojure] [pomegranate/pomegranate])]
[clucy/clucy "0.2.2" :exclusions ([org.clojure/clojure])]]
dependencies))))

(defn add-seven [project]
(assoc project :seven 7))
Expand Down
2 changes: 1 addition & 1 deletion test/leiningen/test/pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
((partial mapcat :content))))))

(deftest test-pom-handles-global-exclusions
(is (= [["clojure"] ["clojure"] ["clojure"]]
(is (= [["clojure"] ["clojure"]]
(-> (make-pom (with-profile-merged sample-project
^:leaky {:exclusions '[org.clojure/clojure]}))
parse-xml
Expand Down

0 comments on commit 34b4981

Please sign in to comment.