Skip to content

Commit

Permalink
Don't allow release versions that depend upon snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Dec 9, 2010
1 parent 887d75d commit cc62c1a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
19 changes: 12 additions & 7 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ This becomes:
Sometimes versions will end in "-SNAPSHOT". This means that it is not
an official release but a development build. Relying on snapshot
dependencies is discouraged but is sometimes necessary if you need bug
fixes, etc. that have not made their way into a release yet. Adding a
snapshot dependency to your project will cause Leiningen to actively
go seek out the latest version of the dependency once a day when you
run <tt>lein deps</tt>, (whereas normal release versions are cached in
the local repository) so if you have a lot of snapshots it will slow
things down.
fixes, etc. that have not made their way into a release yet. However,
snapshot versions are not guaranteed to stick around, so it's
important that released code never depends upon snapshot versions that
you don't control. Adding a snapshot dependency to your project will
cause Leiningen to actively go seek out the latest version of the
dependency once a day when you run <tt>lein deps</tt>, (whereas normal
release versions are cached in the local repository) so if you have a
lot of snapshots it will slow things down.

Speaking of the local repository, all the dependencies you pull in
using Leiningen or Maven get cached in $HOME/.m2/repository since
Expand Down Expand Up @@ -158,7 +160,10 @@ instead of a single version:

See [Maven's version range
specification](http://maven.apache.org/plugins/maven-enforcer-plugin/rules/versionRanges.html)
for details.
for details. Don't do this unless you have manually confirming that it
works with each of those versions though. You can't assume that your
dependencies will use semantic versions; some projects even introduce
backwards-incompatible changes in bugfix point releases.

## Dev Dependencies

Expand Down
9 changes: 9 additions & 0 deletions src/leiningen/pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
It should not be considered canonical data. For more information see
https://github.com/technomancy/leiningen -->\n")

(defn check-for-snapshot-deps [project]
(when (and (not (re-find #"SNAPSHOT" (:version project)))
(not (System/getenv "LEIN_SNAPSHOTS_IN_RELEASE"))
(some #(re-find #"SNAPSHOT" (second %)) (:dependencies project)))
(throw (Exception. (str "Release versions may not depend upon snapshots."
"\nSet the LEIN_SNAPSHOTS_IN_RELEASE environment"
" variable to override this.")))))

(defn make-pom
([project] (make-pom project false))
([project disclaimer?]
(check-for-snapshot-deps project)
(with-open [w (StringWriter.)]
(.writeModel (MavenProject. (make-model project)) w)
(when disclaimer?
Expand Down
5 changes: 5 additions & 0 deletions test/test_pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
(let [model (make-model test-project)]
(is (= "src" (-> model .getBuild .getSourceDirectory)))
(is (= "test" (-> model .getBuild .getTestSourceDirectory)))))

(deftest test-snapshot-checking
(is (thrown? Exception (pom (assoc test-project
:version "1.0"
:dependencies [['clojure "1.0.0-SNAPSHOT"]])))))
2 changes: 1 addition & 1 deletion test_projects/sample/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; just want a basic project to work from, generate a new one with
;; "lein new".

(def clj-version "1.1.0-master-SNAPSHOT")
(def clj-version "1.1.0")

(defproject nomnomnom "0.5.0-SNAPSHOT"
:description "A test project"
Expand Down

0 comments on commit cc62c1a

Please sign in to comment.