I wanted to use Rake as a build tool but there was an obvious hurdle to clear; all those Java specific tasks that we take for granted in Ant aren't available in the Ruby libraries. For example, let's say a Rake script needs to kick off a Java process. The core Ruby libraries make this possible:
system("java", "-client -jar lib/foobar.jar")
<java classpath="lib/foobar.jar" classname="foo.bar.FooBar" fork="true">
<jvmarg value="client"/>
<arg value="argOne"/>
<arg value="argTwo"/>
</java>
@ant = AntProject.new(:ant_home => "/Users/caleb/tools/apache-ant-1.7.0")
@ant.java(:classpath => 'lib/foobar.jar', :classname => 'foo.bar.FooBar',
:fork => 'true'){
jvmarg(:value => 'client')
arg(:value => 'argOne')
arg(:value => 'argTwo')
}
Here is a more complicated example using the javac task. This simply illustrates that all of the normal Ant tasks are at your disposal, including Ant Properties and Refs:
@ant = AntProject.new(:ant_home => "/Users/caleb/tools/apache-ant-1.7.0")
@ant.property(:name => 'common.dir', :value => @current_dir)
@ant.path(:id => "other.class.path"){
pathelement(:location => "classes")
pathelement(:location => "config")
}
@ant.path(:id => "common.class.path"){
fileset(:dir => "${common.dir}/lib"){
include(:name => "**/*.jar")
}
pathelement(:location => "${common.classes}")
}
@ant.javac(:srcdir => "test", :destdir => "classes"){
classpath(:refid => "common.class.path")
classpath(:refid => "other.class.path")
}
<target name="clean" depends="init">
<delete dir="classes" failonerror="false"/>
<delete dir="${distro.dir}"/>
<delete file="${outputjar}"/>
<delete file="${output.dir}"/>
</target>
task :clean => [:init] do
@ant.delete(:dir => "classes", :failonerror => "false")
@ant.delete(:dir => "${distro.dir}")
@ant.delete(:file => "${outputjar}")
@ant.delete(:file => "${output.dir}")
end
Antwrap runs on the native Ruby and the JRuby interpreter. If running on the native Ruby interpreter, Antwrap depends on the Ruby Java Bridge (RJB) Gem which invokes Java classes via the Java Native Interface (JNI). Antwrap is currently being used for Ant tasks in the Raven (a.k.a. don't call me Maven) project. Raven is a JRuby implementation of the Rake tool that provides all kinds of utilities for a Java project.
In the long-term, I see Ruby/Rake scripts complementing a tool like Maven on Java projects. Ruby for fine-grained, project specific tasks and Maven for coarse-grained, boiler-plate tasks (compilation, unit-tests, packaging, documentation) that you need on most Java projects.
Other resources:
Martin Fowler on JRake
Groovy Antbuilder