Setting up a Clojure Project with Maven

In this blog post I’m going to record my recent experience in setting up a Clojure project using the clojure-maven-plugin.


First you need to compile the plugin from source:
git clone git://
cd clojure-maven-plugin
mvn install
Of course, you will need to have Maven2 installed already.

After that, the compiled plugin jar will be in your maven local repository. Create a pom.xml file to use the plugin. I’m using the pom.xml from my project Programming Collective Intelligence as an example:

<project xmlns="" xmlns:xsi=""
    <name>Programming Collective Intelligence</name>



Also, setting up clojure-lang and clojure-contrib (optional, but nice to have) as dependencies as follows:


Clojure builds haven’t reached Maven central repository yet, so you need to build Clojure from source, and install it into your local repository by using
mvn install:install-file -Dfile=clojure-lang.jar -DgroupId=org.clojure -DartifactId=clojure-lang -Dversion=1.1.0-alpha-SNAPSHOT -Dpackaging=jar

Do the same for clojure-contrib.

You can also create a directory in under your project root and have pom.xml looking for artifacts in that directory as well. I found this to be useful for artifacts that are not in the central repository. To do so, add repository definition in pom.xml:


Afterwards, you need to setup your directory structure as follows:

-- lib-repo
    -- org.clojure
        -- jars
            * clojure-lang-1.1.0-alpha-SNAPSHOT.jar
            * clojure-contrib-1.1.0-alpha-SNAPSHOT.jar
        -- poms
            * clojure-lang-1.1.0-alpha-SNAPSHOT.pom
            * clojure-contrib-1.1.0-alpha-SNAPSHOT.pom

The pom files can be found in your local repository after you’ve done mvn install:install-file.

If you want to run clojure:repl goal, you’d better add jline to your dependency as well:



By convention, the plugin compiles everything under ${project_root}/src/main/clojure and ${project_root}/src/test/clojure.

It’s hard to imagine working in a language like Clojure without automated unit tests. Fortunately, clojure-maven-plugin has the clojure:test goal which runs unit tests. All you need to do is telling the plugin where’s the entry point of your unit test. Add the following configuration in the build section:


The test script looks like the following:

(ns my-namespace
  (:use clojure.contrib.test-is
(run-tests 'test-module-n)

There you have it! The sample files can be found in my pci-clj project on GitHub.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: