Mostly out of pure stubbornness, I’ve resolved to use vim as my editor of choice while I build a small compiler in front of the audience at my OSCON presentation next week. Whilst messing with Maven POM files for the umpteenth time to get my Scala code compiling, I got frustrated and figured there must be a better way to do this crap that didn’t involve 150 lines of XML.
Turns out there is: meet Apache Buildr.
: http://buildr.apache.org “Apache Buildr”
As an example, here’s a Buildfile that I was using earlier:
require "buildr/scala" Buildr.settings.build["scala.version"] = "2.8.1" define "oscon" do project.version = "0.1.0" test.using :junit compile.with "org.apache.bcel:bcel:jar:5.2" package :jar end
Then from the command line I run this:
$ buildr package
At this point, Buildr downloads Apache BCEL (a dependency of my project) compiles all Scala code within $ROOT/src/main/scala, runs my JUnit tests in $ROOT/src/test/scala and packages the resulting class files into $ROOT/target before packaging them up into a nice JAR file.
Better still, you can run it within any subdirectory in your project — Buildr will walk up the directory tree looking for a Buildfile to execute.
I tried doing the same thing in Maven and came out some 140 lines of XML worse off.
Of course, I’m just scratching the surface of what’s possible with Buildr here. It’s also very extensible: I wrote a little plugin to support compilation of Mirah using Buildr: buildr-mirah. Surprisingly easy — took me a few hours from scratch (which included tracking down and submitting a fix for a bug in the Antwrap dependency!). You require “buildr/mirah”, drop your code in src/main/mirah and you’re set.
Seriously. Check out Buildr. IDE die-hards will miss the tooling, but for command-line junkies I’m yet to see a nicer solution.