Search This Blog

Loading...

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:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html

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
user=>

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=0.0.0.0/0.0.0.0,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:



<project>

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>hello-maven-clojure-swank</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>hello-maven</name>
  <description>maven, clojure, emacs: together at last</description>

  <repositories>
    <repository>
      <id>clojars</id>
      <url>http://clojars.org/repo/</url>
    </repository>
    <repository>
      <id>clojure</id>
      <url>http://build.clojure.org/releases</url>
    </repository>
    <repository>
      <id>central</id>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>org.clojure</groupId>
      <artifactId>clojure</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.clojure</groupId>
      <artifactId>clojure-contrib</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
      <groupId>jline</groupId>
      <artifactId>jline</artifactId>
      <version>0.9.94</version>
    </dependency>
    <dependency>
      <groupId>swank-clojure</groupId>
      <artifactId>swank-clojure</artifactId>
      <version>1.2.0-break-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.theoryinpractise</groupId>
        <artifactId>clojure-maven-plugin</artifactId>
        <version>1.3.2</version>
      </plugin>
    </plugins>
  </build>

</project>

3 comments:

  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.

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

    http://github.com/talios/clojure-maven-plugin/issues#issue/10

    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:

    http://github.com/talios/clojure-maven-plugin/issues#issue/5

    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.

    ReplyDelete
  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.

    ReplyDelete

Followers