Raven: Building Java with Ruby
I haven’t been writing for quite a while now and that’s because I’ve been busy. I’ve been working on some sort of pet project: Raven. The idea is to use a really powerful language that can elegantly address scripting in build scripts: Ruby.
The good thing is I didn’t have to start from the ground up, Ruby already has two very neat and robust tools that helped me quite a lot: Rake and RubyGems. Here is how I leveraged them:
- I’ve used RubyGems to solve the dependency problem. Java jars are wrapped in a Gem. That’s all. From there RubyGem does all the job of looking up needed dependencies, managing local and remote repositories, installing the dependencies, handling the different versions.
- I’ve used Rake to solve the build script and task problem. It makes it easy for you to create a build script with different tasks an tasks prerequisites. And from there, hey, it’s plain Ruby!
Now you could be wondering what Raven is doing after all, if all these features are already provided. Here we go:
- First it does all the wrapping work, importing either your local Maven (1 or 2) repository into the local Gem repository or building a remote Gem repository. So if you’re already using Maven you can get started really, really quickly. If you don’t, you’ll just have to setup your own repository, Raven makes it easy.
- Second it manages your dependencies. Or more precisely it talks to Gem to check where your dependencies can be found and install them locally. These installed Gems will then be used to build your classpath.
- Third and finally, it provides a set of already defined Rake tasks for the most common operations. Things like compiling, building a jar from your classes, javadoc, etc …
To illustrate, this is a simple “Hello World” style example of a rakefile that could be used to build a project:
require 'raven' require 'rake/clean' set_sources(["http://localhost:2000"]) CLEAN.include(’target’) dependency ‘compile_deps’ do |t| t.deps << [{'commons-logging' => '1.0.4'}, 'commons-pool'] t.deps << ['commons-lang', 'wsdl4j', 'log4j'] end javac ‘compile’ => ‘compile_deps’ do |t| t.build_path << “src/main/java” end jar ‘ode-utils.jar’ => ‘compile’
The best part of it is it’s quite plain Ruby. So you can simply script your build the way you want to! No more XML fighting or plugin fiddling! So if you feel that this cool could fit your needs, just check it out!
P.S. This idea came during a lunch break with Assaf, we were discussing the pains of the different solutions in Java to get a build done, when Ruby had such excellent tools. So thanks man for your great ideas!
Comments(8)