Building Java with JRuby

Posted by aslak.hellesoy

Both of my former colleagues "Martin Fowler":http://martinfowler.com/ and "Foemmel":http://blog.foemmel.com/ want to use Rake to build Java. In addition to writing my scripts in Rake (Ruby with basic task constructs) I also want to leverage the functionality provided by "Ant":http://ant.apache.org/ and "Maven":http://maven.apache.org/. The space of build tools for Java based on JRuby and one of or more of Rake, Ant and Maven is already getting crowded. So far the most promising attempts are: * "Raven":http://raven.rubyforge.org/ (JRuby wrapper for Rake, RubyGems and Maven) * "AntBuilder":http://antbuilder.rubyforge.org/ (JRuby wrpper for Ant) * "JRake":http://blog.foemmel.com/jrake (JRuby wrapper for Rake) They all have their strengths and weaknesses, and my hope is that by highlighting some of these, it won't be long until we have top-notch JRuby-based build tools for Java, hopefully with the authors of all of these tools putting their heads together. h2. Raven Raven seems to be the most mature of these tools. It's Rake based and integrates Maven repositories and dependency handling with RubyGems - the package manager for Ruby. h3. Good The fact that it is Rake based is a huge plus for me. Of all the build "languages" I have used it is the best I have seen so far. The fact that it manages dependencies by tapping into Maven repositories (without using the Maven code it seems), using RubyGems also seems appealing. h3. Bad Instead of leveraging existing Ant tasks (like AntBuilder), it only provides a few of its own. This is a huge setback for people who expect to find the same functionality as in Ant. h2. AntBuilder It's essentially a "builder":http://builder.rubyforge.org/ wrapper around Ant that lets you mark up Ant tasks like this:

require 'builder/antbuilder'

ant = Builder::AntBuilder.new  
...
ant.copy(:todir => @jruby_classes_dir) {
  ant.fileset(:dir => @src_dir, :includes => "**/*.properties")
}
h3. Good It lets you use *any* Ant task out there right from JRuby. Since it relieves you of the XML masochism you can sprinkle over ifs, loops, blocks etc. h3. Bad It is a bit clunky to use with Rake. If you want to get rid of the redundant ant. you have to subclass Builder::AntBuilder, which has the unfortunate sideeffect of removing you from Rake. h2. JRake JRake is Foemmel's new toy. It's a bare-bones JRuby interface to the core JDK tools with a dash of Jetty on top. h3. Good It is Rake based and it's FAST. It has very low startup time, thanks to a background server (Jetty) that just sits there and listens for build commands, which can be issued from the commandline with a little bash script that uses curl. I'm sure a client for Windows would be easy to make too. h3. Bad None of the goods from the other two (except for being Rake based).