Search This Blog

Wednesday, March 17, 2010

Clojure, Maven, Emacs: An eternal golden braid

This page still gets lots of hits. 
Several people have said that they refer to it often, even though it's out of date. So I'm leaving it up.

There are more recent instructions on getting clojure working quickly here:

It takes about 30 seconds from a fresh install if your internet connection is fast, and at that point you've got a usable REPL and emacs setup.

It basically goes: install maven, install emacs, make pom, copy cryptic thing into emacs, press magic keys, press i three times, press x and you're done.

I use that page if I need to install from scratch these days.

Here's the original post:

Maven is a horror from the depths of the Java pit.
But on investigation I find I rather like it:

Install maven (actually maven2) with

$ sudo apt-get install maven2

and then put the xml you'll find below in a file called pom.xml .

Put pom.xml in its own directory, and type

$ mvn clojure:repl

At this point, maven will begin to download the entire internet. This is normal. Go and make a cup of tea. It will only need to do it once.

When you get back, the following prompt should be waiting for you:

Clojure 1.1.0

Go ahead and play: clojure-contrib is already on the classpath ; Jline is running, so the repl is usable.

But it gets better:

$mvn clojure:swank

leads to:

Connection opened on local port  4005
#<ServerSocket ServerSocket[addr=,port=0,localport=4005]>

So if you've got a clojure-compatible SLIME installed in EMACS then a simple M-x slime-connect will allow you to connect to the running image.

Now at this point, we've already short-circuited a large amount of the unpleasantness which would usually be involved in setting up Clojure.

But in fact this is not what I like about using maven.

From here on in a lot of tedious and annoying tasks to do with versions and classpaths and tests and libraries and setting up interactive development become very easy and automatic.

I have almost stopped missing PLT scheme's excellent PLaneT system.

There will be further posts.

Here is the pom file:


  <description>maven, clojure, emacs: together at last</description>






  1. This matches my experience with leinengen (which nicely replaces the long XML POM with a short bit of sexpr) also.

    Bad: "download the entire internet."

    Good: YOU didn't have to go find and download all that stuff, and your dependency the identified versions is crispy defined.

    Maven has its issues, but overall it is a big win.

  2. This is broken under windows. I've made a bug report:

    After someone told me about this, I went to use Windows for about the first time in ten years, and came independently to exactly this fix:

    Which was posted as a bug some months ago.

    Unfortunately, although this works fine under Windows, it breaks it under Ubuntu.

    I have no idea what's going on (something to do with how the Windows/bash command lines parse escaping differently?).

    However it's easy enough to make a local copy that works under windows.

    Get plugin from Github.
    Apply patch
    Change version no of plugin in *both* pom.xml files.
    (the one above and the one for the plugin)

    Use mvn install in the plugin directory to create a local plugin with the new version number in your local repository.

    Use mvn clojure:swank with the above pom.

  3. Oh where oh where was this post when I was struggling to get Aquamacs working!!! Thanks. I HATE maven. It is god awful software. But this time, as in many, it worked just fine and really made it simple.