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).
Maven-style dependency management can be found using Ivy, which comes with Ant tasks. Can you easily use custom Ant tasks with JRake?
For now I think the only one of these tools that lets you use arbitrary Ant tasks is AntBuilder. However, AntBuilder seems dormant, so it would be nice if someone picked it up again.
Actually I’ve been thinking about integrating AntBuilder with Raven. I still rather stick with the ‘native’ tasks for the basic java stuff (like javac, javadoc, jar, ...) as they’re rake-based and therefore more flexible. But using AntBuilder as a complement for all these little things that already exist in Ant and won’t in Raven would be nice (thinking of XDoclet or XMLBeans here for example).
Wha! XDoclet! Are people still using such arcane tools? (I wrote big parts of it :-D)
It would be great to be able to do what you say though!
Hi Uma,
1) It depends on what the individual developers of these tools decide to do, and whether others start to contribute to them. I’m not directly involved with any of them, but I’m pretty sure that a lot will happen – I just don’t know what yet.
2) Translating a build.xml into a JRuby AntBuilder-style document would be pretty straightforward I would think. It’s just parsing XML and emitting builder code. In order for such a translation to be runnable with Rake/Ruby we’d have to see some better integration (or perhaps merging) of AntBuilder (not Rake based) with Raven and/or JRake (Rake based).
Interested in helping out? ;-)
I’m the original AntBuilder developer. I have no time to maintain AntBuilder anymore. I’m in the process of signing up another comitter who is using AntBuilder in their day job (hurrah!). Note that AntBuilder should be installed as a gem (from jruby) and the instructions on the AntBuilder home page have been updated to indicate this: “gem install AntBuilder”. I’ve just done a gem release that works with the latest JRuby 1.9.8.
I also noticed that there is a new rubyforge project called antwrap which looks like it takes a lighter weight approach than AntBuilder and coold be very promising. I haven’t looked at it in any detail though.
Hi Aslak,
Tim Azzopardi pointed me to you blog (thanks Tim). I started a project on Rubyforge called ‘Antwrap’ which can be used to invoke Ant tasks from a JRuby project. Syntactically, Antwrap is very similar (if not identical) to AntBuilder. One difference between the two approaches is that Antbuilder uses some third party API’s to invoke Ant, whereas Antwrap invokes the Ant classes directly.
The Antwrap library can be run in both declarative, and non-declarative mode. In non-declarative mode, you can assign an Ant task to a variable and invoke the task at a later point in the code path. For example;
@ant = AntProject.new({:name=>”FooProject”, :declarative=> false})
...some code creates the various path references in the javac task below
javac_task = @ant.javac(:srcdir => “test”, :destdir => “classes”){ classpath(:refid => “common.class.path”) classpath(:refid => “foo.class.path”) }
javac_task.execute
The non-declarative mode is an option on the Project instance and is not the default. Take a look at the documentation here: http://antwrap.rubyforge.org/
Antwrap is available as a gem and is currently a beta release. The folks on the Raven project have indicated that they will use Antwrap in their tool for Ant tasks. I would love to have some feedback on the library (shortcomings, bugs, ideas, etc) in order to improve it.