Building a Clojure project

What This Guide Covers #

For Language versions and other build-environment specific information visit our reference pages:

This guide covers build environment and configuration topics specific to Clojure projects. Please make sure to read our Tutorial and general build configuration guides first.

Clojure builds are not available on the macOS environment.

CI Environment for Clojure Projects #

Travis CI environment provides a large set of build tools for JVM languages with multiple JDKs, Ant, Gradle, Maven and both Leiningen 1.7.x and 2.4.x (default).

Dependency Management #

If you use Leiningen, it will automatically install any dependencies that are listed in the project.clj file.

Alternate Install Step #

If you need to install other dependencies before your tests can run, you should set up the proper :hooks in project.clj.

If for some reason you can’t use hooks,you can override the install step in your .travis.yml:

install: lein protobuf install

See the build configuration guide to learn more.

Build Script #

Using Midje #

If your project uses Midje, make sure lein-midje is on your project.clj development dependencies list and override script: in .travis.yml to run the Midje task:

script: lein midje

For Leiningen 1 add :dev-dependencies to project.clj:

:dev-dependencies [[midje "1.4.0"]
                   [lein-midje "1.0.10"]])

Leiningen 2 replaces :dev-dependencies with profiles:

:profiles {:dev {:dependencies [[midje "1.6.3"]]
                 :plugins [[lein-midje "3.0.0"]]}}

Please note that for projects that only support Clojure 1.3.0 and later versions, you may need to exclude transient org.clojure/clojure for Midje in project.clj:

:dev-dependencies [[midje "1.4.0" :exclusions [org.clojure/clojure]]
                   [lein-midje "1.0.10"]])

For real world example, see Knockbox.

Using Speclj on Travis CI #

If your project uses Speclj, make sure it is listed in your development dependencies in project.clj, and include this script: line in .travis.yml:

script: lein spec

For Leiningen 1, Speclj should be listed under :dev-dependencies in project.clj:

:dev-dependencies [[speclj "3.3.1"]]

Leiningen 2 replaces :dev-dependencies with profiles:

:profiles {:dev {:dependencies [[speclj "3.3.1"]]}}

Using Leiningen 1 #

Leiningen 1 is provided side by side with 2.4.x. To use it, specify lein key in .travis.yml:

lein: lein1

In case you need to use lein binary in before_script, install:, script: commands and so on, use lein1:

before_install:
  - lein1 bootstrap

Build Config Reference #

You can find more information on the build config format for Clojure in our Travis CI Build Config Reference.

Task chaining requires using the do task:

script: lein1 do javac, test

Testing Against Multiple JDKs #

As for any JVM language, it is also possible to test against multiple JDKs.

Examples #

Testing Against Multiple Versions of Clojure #

With Leiningen 1 #

Leiningen has an excellent plugin called lein-multi that lets you effortlessly test against multiple versions of Clojure (for example, 1.3, 1.4 and alphas/betas/snapshots of the most recent development version). Because leiningen can run tests against any version of Clojure (not necessary the same version as Leiningen itself uses), there is no need for runtime switchers (like RVM) for Clojure.

To use lein-multi on Travis CI, add it to :plugins in project.clj (note, this feature is only available starting with Leiningen 1.7.0) and override script: to run lein multi test instead of default lein test:

language: clojure
script: lein1 multi test

For a real world example, see Monger.

With Leiningen 2 #

Leiningen 2 has a core feature that replaces lein-multi: Profiles. To run your tests against multiple profiles (and thus, multiple dependency sets or Clojure versions), use lein with-profile command like so:

lein: lein
script: lein with-profile dev:1.4 test

where dev:1.4 is a colon-separated list of profiles to run test task against. Use lein profiles to list your project’s profiles and lein help with-profile to learn more about the with-profiles task.

Using a more recent versions of Leiningen #

If your Clojure project requires a more recent version of Leiningen, you can specify it with:

language: clojure

lein: 2.6.1 # version 2 and up

The job will install the specified version of Leiningen if it is not pre-installed, and move on to install your project’s dependencies.

Example #

For a real world example, see Neocons.

Examples #