Gradle + Clojure = clj-gradle
I’m not a maven fan. I use it with lift, but that’s pretty much it. In short, I only use it when I’m forced to. So when Gradle came along, I adapted it pretty early on. If you don’t know what Gradle is. Check it out here. It has extensive documentation, which is very impressive considering the project is so young.
When Meikel Brandmeyer announced he wrote clj-gradle, I really wanted to try it out. I finally found time to give it a spin. I ran into a few bumps, but I did get it to work. Here is what I did, step by step.
Get the source. You need mercurial. Use “hg clone http://bitbucket.org/kotarak/clj-gradle/”
In the directory, “mkdir lib”, then put clojure-1.0.0.jar in lib.
Check the build.gradle file, the version number should be set to 1.0.0
Issue “gradle build”. You should get a build successful. The file clj-gradle-1.0.0.jar is created under build/libs.
You are done. Time to try it out.
Create a new sandbox directory. Then issue “mkdir lib”, you need to put both clj-gradle-1.0.0.jar clojure-1.0.0.jar in lib.
I followed the README and created src/main/clojure/test/example.clj, then pasted in the code from it.
(ns test.example (:gen-class)) (defn -main [] (println "Hello, World!"))
I then use the build script from README, with a few changes to put in specific version number.
buildscript {
repositories {
flatDir name: 'lib', dirs: 'lib'
}
dependencies {
classpath name: 'clj-gradle-1.0.0'
}
}
usePlugin(de.kotka.gradle.ClojurePlugin)
repositories {
flatDir name: 'lib', dirs: 'lib'
}
configurations {
compileOnly {
setVisible(false)
setTransitive(false)
}
compile.extendsFrom(compileOnly)
}
dependencies {
compileOnly name: 'clj-gradle-1.0.0'
compile name: 'clojure-1.0.0'
}
Now issue “gradle build”, you should get a build successful. To run it, I used “java -cp lib/clojure-1.0.0.jar:build/libs/cljgradletest-unspecified.jar test.example” I used cljgradletest-unspecified.jar because the name of my sandbox directory is cljgradetest. All goes well, you’ll see the “Hello, World!” output. Congratulation, your clojure project is now backed by Gradle.


[...] those who dislike Maven: #gradle and #clojure together, clj-gradle step by step (here, via @wmacgyver) Share and [...]
[...] the clj-gradle-1.0.0.jar and build.gradle file. If you don’t have the clj-gradle-1.0.0.jar go here to see how to build [...]
One can also use the Download tab on bitbucket to download a revision. So one does not need to have mercurial installed.