Maven Snapshots

Or: How to use Maven snapshots without setting your hair on fire.

Ever depended on a Clojure library with a version that ended in -SNAPSHOT? That's what's called a Maven snapshot.

Maven snapshots are a handy tool to provide pre-release builds to those who are interested. In contrast to proper releases a SNAPSHOT release can be "updated". And that's where the trouble comes in.

Let's say you depend on a snapshot because it contains a fix you recently contributed to your favorite open source project. A week later another fix is added and released under the same 0.1.0-SNAPSHOT version.

Now it turns out that second fix contained a minor bug. No big deal, it's a pre-release after all. The problem with all this however is that you (Maven) will automatically use the new SNAPSHOT, no action required. A dependency you use in your project changes without you being aware of it. Suddenly stuff breaks. You wonder what happened. Did you change anything? No? Frustration ensues.

Because of this for a long time I thought SNAPSHOTS are evil and instead of using them library authors should release development builds with a qualifier like 0.1.0-alpha1. I still think this is a good practice and try to adhere to it myself as much as possible.

In the meantime there is another way to safely depend on Maven snapshots though.

Whenever you push a SNAPSHOT version to a Maven repository (like Clojars) it does not actually overwrite the previously uploaded jar but creates a separate jar with a version like this: 0.1.0-20170301.173959-4. Once the upload is complete it merely changes the SNAPSHOT version to point to that release. All previous releases are still available (by default Maven repos only keep the latest SNAPSHOT version but Clojars keeps them all).

This means instead of depending on a mutable version you can now depend on an immutable version. Oh do we love immutability.

[group-id/project-id "0.1.0-20170301.173959-4"]

Finding these version identifiers isn't the easiest thing but basically:

  1. you go to the page of a jar on Clojars, e.g. adzerk/boot-cljs
  2. in the sidebar that lists recent versions, click "Show All Versions"
  3. versions page you can find a note at the bottom that leads you to the Maven repository
  4. if you click on a SNAPSHOT version there you get to a page that lists all the stable identifiers for that version

To get to the Maven repo page directly you can also just put a repo. subdomain in front of a given Clojars project url:

And they depend on SNAPSHOTs happily ever after.

Other Posts

  1. Requiring Closure NamespacesMay 2017
  2. Simple Debouncing in ClojureScriptApril 2017
  3. Making Remote WorkMarch 2017
  4. Just-in-Time Script Loading With React And ClojureScriptNovember 2016
  5. Props, Children & Component Lifecycle in ReagentMay 2016
  6. Om/Next Reading ListNovember 2015
  7. Parameterizing ClojureScript BuildsAugust 2015
  8. ClojureBridge BerlinJuly 2015
  9. Managing Local and Project-wide Development Parameters in LeiningenJune 2015
  10. Formal Methods at AmazonApril 2015
  11. (lisp keymap)February 2015
  12. CLJSJS - Use Javascript Libraries in Clojurescript With EaseJanuary 2015
  13. Why Boot is Relevant For The Clojure EcosystemNovember 2014
  14. S3-Beam — Direct Upload to S3 with Clojure & ClojurescriptOctober 2014
  15. Patalyze — An Experiment Exploring Publicly Available Patent DataOctober 2014
  16. Running a Clojure Uberjar inside DockerSeptember 2014
  17. Using core.async and Transducers to upload files from the browser to S3September 2014
  18. Emacs & VimJuly 2014
  19. Heroku-like Deployment With Dokku And DigitalOceanMarch 2014
  20. Woodworking MasterclassesFebruary 2014
  21. Early Adopters And Inverted Social ProofFebruary 2014
  22. Living SmallFebruary 2014
  23. Sending You a TelegramJanuary 2014
  24. Running a Marathon, Or NotJanuary 2014
  25. Code SimplicityJanuary 2014
  26. What do we need to know?December 2013
  27. Sculley's DiseaseDecember 2013
  28. A Resurrection PostDecember 2013
  29. A Trip To The USSeptember 2013
  30. Analytics DataApril 2013
  31. Asynchronous CommunicationApril 2013
  32. From Zero to Marathon in Six MonthtsMarch 2013
  33. Git Information in Fish Shell’s PromptDecember 2012
  34. When We Build StuffAugust 2012
  35. Models, Operations, Views and EventsJuly 2012
  36. The Twelve Factor AppJune 2012
  37. Paris And BackMay 2012
  38. A Friend Is Looking For A Summer InternshipMay 2012
  39. Kandan Team ChatMay 2012
  40. Startups, This Is How Design WorksMarch 2012
  41. Entypo Icon SetMarch 2012
  42. Hosting A Static Site On Amazon S3February 2012
  43. Exim4 Fix Wrongly Decoded Mail SubjectJanuary 2012