[#1123, #1124] Do not require java for bb tasks without deps

This commit is contained in:
Michiel Borkent 2021-12-30 16:32:15 +01:00
parent 890877fcfd
commit 34f9997df4
3 changed files with 41 additions and 28 deletions

2
sci

@ -1 +1 @@
Subproject commit f29089b68e2e7d41e9491be0c1d7c48e1b9691e7
Subproject commit aaf5821f8c084d6301c96da88f05c570bffcc84d

View file

@ -66,11 +66,15 @@
paths)
paths)]
(cp/add-classpath (str/join cp/path-sep paths))))
(when-let [deps-map (not-empty (dissoc deps-map
(let [need-deps? (or (:deps deps-map)
(and (:aliases deps-map)
aliases))]
(when need-deps?
(let [deps-map (dissoc deps-map
;; paths are added manually above
;; extra-paths are added as :paths in tasks
:paths
:tasks :raw :min-bb-version))]
:paths :tasks :raw :file :deps-root
:min-bb-version)]
(binding [*print-namespace-maps* false]
(let [deps-map (assoc-in deps-map [:aliases :org.babashka/defaults]
{:replace-paths [] ;; babashka sets paths manually
@ -90,7 +94,7 @@
(apply deps/-main args)))
cp (str/trim cp)
cp (str/replace cp (re-pattern (str cp/path-sep "+$")) "")]
(cp/add-classpath cp))))))
(cp/add-classpath cp))))))))
(def deps-namespace
{'add-deps (sci/copy-var add-deps dns)

View file

@ -5,6 +5,7 @@
[babashka.impl.common :as common]
[babashka.main :as main]
[babashka.test-utils :as test-utils]
[borkdude.deps]
[clojure.edn :as edn]
[clojure.string :as str]
[clojure.test :as test :refer [deftest is testing]]))
@ -362,3 +363,11 @@
(is (= 1 (count entries)))
(is (= (fs/parent config) (fs/parent entry)))
(is (str/ends-with? entry "src"))))))
(deftest without-deps-test
(when-not test-utils/native?
(with-redefs [borkdude.deps/-main (fn [& _]
(throw (ex-info "This ain't allowed!" {})))]
(testing "bb.edn without :deps should not require deps.clj"
(test-utils/with-config '{:tasks {a 1}}
(bb "-e" "(+ 1 2 3)"))))))