An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Testing your project against multiple versions of Clojure

December 18, 2011 ·

As Clojure continues to evolve, it's a good idea to ensure your projects work with multiple versions of Clojure so that you are prepared for the future. Luckily, Leiningen makes that easy with a plugin called lein-multi which allows you to specify multiple sets of project dependencies and run tests against all of them automatically.

Here is a project.clj file that has Clojure 1.3.0 as it's normal dependency but uses lein-multi to provide automated testing against Clojure 1.2.1, the latest alpha of Clojure 1.4.0 and the "nightly" build of 1.4.0:

;; all your dependencies except Clojure itself
(def main-deps '[...])

;; your project definition
(defproject myproject "0.0.1-SNAPSHOT"
  :description "My Cool Project"
  :dev-dependencies [[lein-multi "1.1.0-SNAPSHOT"]]
  :repositories [["sonatype-snapshots"
                  "https://oss.sonatype.org/content/repositories/snapshots/"]]
  :dependencies ~(conj main-deps
                       '[org.clojure/clojure "1.3.0"])
  :multi-deps {"1.2x" ~(conj main-deps
                             '[org.clojure/clojure "1.2.1"])
               "1.4A" ~(conj main-deps
                             '[org.clojure/clojure "1.4.0-alpha3"])
               "1.4S" ~(conj main-deps
                             '[org.clojure/clojure "1.4.0-master-SNAPSHOT"])}
  ... ; other options
  )

You need the repositories option so Leiningen looks at the snapshot repository for *-master-SNAPSHOT builds of Clojure.

lein-multi is shown as a development dependency here but you could also install the plugin for all your projects:

lein plugin install lein-multi "1.1.0-SNAPSHOT"

Assuming you go with lein-multi as a development dependency, just run lein deps to install all the standard dependencies for the project. Now you can use lein-multi to install all the alternative dependencies:

lein multi deps

This will create a multi-lib directory containing sub-folders for each named set of multi-deps in the project.clj file. Now you can run tests against all versions automatically:

lein multi test

All of your normal Leiningen operations will continue to work for your mainline dependencies - lein deps, test - so you can develop as usual, but you can also tests against any sets of dependencies you want.

Please, if you are a library maintainer, consider using lein-multi to ensure your library is staying current with Clojure's development - and, if possible, with Clojure 1.2.1 so you are offering the best migration path for developers who have not yet moved to Clojure 1.3.0.

Tags: clojure

0 responses