diff --git a/doc/PROFILES.md b/doc/PROFILES.md index d39091e3..2ca7cd14 100644 --- a/doc/PROFILES.md +++ b/doc/PROFILES.md @@ -7,7 +7,7 @@ without including them in the jar, or you may want to have Swank Clojure available in every project you hack on without modifying every single project.clj you use. -By default the `:dev`, `:user`, and `:default` profiles are activated +By default the `:dev`, `:user`, and `:base` profiles are activated for each task, but the settings they provide are not propagated downstream to projects that depend upon yours. Each profile is defined as a map which gets merged into your project map. @@ -74,19 +74,6 @@ vectors even though they behave like maps (because it only makes sense to have a single version of a given dependency present at once). The replace/displace metadata hints still apply though. -## Composite Profiles - -Sometimes it is useful to define a profile as a combination of other -profiles. To do this, just use a vector instead of a map as the profile value. -This can be used to avoid duplication: - -```clj -{:shared {:port 9229, :protocol \"https\"} - :qa [:shared {:servers [\"qa.mycorp.com\"]}] - :stage [:shared {:servers [\"stage.mycorp.com\"]}] - :production [:shared {:servers [\"prod1.mycorp.com\", \"prod1.mycorp.com\"]}]} -``` - ## Activating Profiles Another use of profiles is to test against various sets of dependencies: @@ -114,6 +101,24 @@ Multiple profiles may be executed in series with colons: $ lein with-profile 1.3:1.4 test :database +## Composite Profiles + +Sometimes it is useful to define a profile as a combination of other +profiles. To do this, just use a vector instead of a map as the profile value. +This can be used to avoid duplication: + +```clj +{:shared {:port 9229, :protocol \"https\"} + :qa [:shared {:servers [\"qa.mycorp.com\"]}] + :stage [:shared {:servers [\"stage.mycorp.com\"]}] + :production [:shared {:servers [\"prod1.mycorp.com\", \"prod1.mycorp.com\"]}]} +``` + +Composite profiles are used by Leiningen internally for the `:default` profile, +which is the profile used if you don't change it using `with-profile`. The +`:default` profile is defined to be a composite of `[:dev :user :base]`, but you +can change this in your `project.clj` just like any other profile. + ## Debugging To see how a given profile affects your project map, use the diff --git a/leiningen-core/src/leiningen/core/project.clj b/leiningen-core/src/leiningen/core/project.clj index 1d076f61..7dcb2e67 100755 --- a/leiningen-core/src/leiningen/core/project.clj +++ b/leiningen-core/src/leiningen/core/project.clj @@ -149,11 +149,12 @@ (def default-profiles "Profiles get merged into the project map. The :dev and :user profiles are active by default." - (atom {:default {:resource-paths ["dev-resources"] - :plugins [['lein-newnew "0.3.4"]] - :checkout-deps-shares [:source-paths - :resource-paths - :compile-path]} + (atom {:default [:dev :user :base] + :base {:resource-paths ["dev-resources"] + :plugins [['lein-newnew "0.3.4"]] + :checkout-deps-shares [:source-paths + :resource-paths + :compile-path]} :leiningen/test {:injections [hooke-injection]} :update {:update :always} :offline {:offline? true} @@ -346,5 +347,5 @@ (ns-unmap 'leiningen.core.project 'project) (-> (reduce apply-middleware @project (:middleware @project)) (merge-profiles profiles))))) - ([file] (read file [:dev :user :default])) + ([file] (read file [:default])) ([] (read "project.clj"))) diff --git a/leiningen-core/test/leiningen/core/test/project.clj b/leiningen-core/test/leiningen/core/test/project.clj index 0ed115c6..e1114b19 100755 --- a/leiningen-core/test/leiningen/core/test/project.clj +++ b/leiningen-core/test/leiningen/core/test/project.clj @@ -149,6 +149,19 @@ (merge-profiles [:a]) (dissoc :profiles)))))) +(deftest test-override-default + (let [expected-result {:A 1, :B 2, :C 3 + :repositories {"central" {:url "http://repo1.maven.org/maven2"} + "clojars" {:url "https://clojars.org/repo/"}} + :dependencies [], :compile-path "classes"}] + (is (= expected-result + (-> {:profiles {:a {:A 1 :B 2} + :b {:B 2 :C 2} + :c {:C 3} + :default [:c :b :a]}} + (merge-profiles [:default]) + (dissoc :profiles)))))) + (deftest test-unmerge-profiles (let [expected-result {:A 1 :C 3 :profiles {:a {:A 1} :b {:B 2} diff --git a/src/leiningen/jar.clj b/src/leiningen/jar.clj index b10b6b2b..3eee8b1b 100644 --- a/src/leiningen/jar.clj +++ b/src/leiningen/jar.clj @@ -195,7 +195,7 @@ Create a $PROJECT-$VERSION.jar file containing project's source files as well as .class files if applicable. If project.clj contains a :main key, the -main function in that namespace will be used as the main-class for executable jar." [project] - (let [project (project/unmerge-profiles project [:default :dev :user])] + (let [project (project/unmerge-profiles project [:default])] (eval/prep project) (let [jar-file (get-jar-filename project)] (write-jar project jar-file (filespecs project [])) diff --git a/src/leiningen/uberjar.clj b/src/leiningen/uberjar.clj index 1eb8ffac..6aa7d38e 100644 --- a/src/leiningen/uberjar.clj +++ b/src/leiningen/uberjar.clj @@ -88,7 +88,7 @@ as well as defining a -main function." (with-open [out (-> standalone-filename (FileOutputStream.) (ZipOutputStream.))] - (let [project (project/unmerge-profiles project [:default :dev :user]) + (let [project (project/unmerge-profiles project [:default]) deps (->> (classpath/resolve-dependencies :dependencies project) (filter #(.endsWith (.getName %) ".jar"))) jars (cons (io/file (jar/get-jar-filename project)) deps)]