Maven, Ant, Rake: JRuby 1.5 Enhances Configuration Management
With its upcoming 1.5 release, anticipated at the end of April, the JRuby project is continuing to improve interoperability between Java and Ruby. Ruby developers will be able to take greater advantage of strengths of the Java platform, while Java developers will find more reasons to mix Ruby tools into their existing projects.
Some of the biggest new features in JRuby 1.5 come in the area of configuration management, with a comprehensive integration of Ant and of Maven repositories into its toolset. JRuby's integration with Maven will bring tens of thousands of new Gems to the JRuby platform, by allowing Java libraries to be installed as Gems:
Thanks to Tamas Cservenak from Sonatype, we now have something once thought impossible: full RubyGems integration of all the Maven artifacts in the world...!
As of JRuby 1.5, you'll be able to install or use in dependencies any Java library ever published to the public Maven repository. In short, you now have an additional 60000-some libraries at your fingertips.
The integration is accomplished via a Maven server that looks like a standard RubyGems repository to JRuby. JRuby users will see the benefit in Java libraries becoming as convenient to use as regular Ruby libraries. This will also make JRuby a more useful choice to enterprises that emphasize library support in evaluating new technologies.
JRuby 1.5 can also help Java developers improve their own dependency management, owing to its integration with Apache's Ant build tool. In a recent blog post, JRuby co-lead Charles Nutter shows how Java developers can manage their dependencies using Ruby's Rake build tool with Apache's Ivy dependency manager, a tool normally called from Ant. Rake can download and install Ivy, use it to fetch jar files and other resources (along with their dependencies) from remote repositories, and make them available to a build. All this is made possible by JRuby 1.5's ability to call Ant tasks from within Rake.
Java developers who wish to lessen their dependence on Ant need not rewrite all their buildfiles from scratch, however. Besides allowing Ant tasks to be invoked from within Rake, JRuby's Rake/Ant integration allows Rake to be called from Ant, as well as allowing Rake tasks to be imported as Ant targets. As JRuby co-lead Tom Enebo writes:
You can just stick a Rakefile off to the side for some new functionality and let your teammates evaluate how much they like it. If they do... [you can] start depending on the capabilities of Rake more by being able to inject Rake tasks into the Ant dependency graph. Your group is still using Ant as the main build tool, but you're delegating more of the build to Rake.
The Rake/Ant integration allows developers to take advantages of the strengths of each:
I think people respect Ant as a tool which is a bit syntactically gross, but which gets the job done reliably. It is also lamented for having little support for imperative programming constructs. This seems to have been by design, but it doesn't seem to make very many programmers happy.
Rake, by contrast, has a much nicer syntax than Ant. It also allows any construct that the Ruby language allows.... On the other hand, if you have the need to perform common tasks in the Java world, then it lacks a bunch of standardized cross-platform tasks that Ant contains. You find yourself breaking out into lots of icky shell commands... and this works great until you try and build something on, gasp, Windows....
Since Rake gives a full imperative programming environment there are some things that are trivial to do in Rake which are cumbersome (or impossible without writing a custom Ant task) in Ant. You can move that stuff into Rake, but still continue using Ant for everything else.
He adds, "Even if you're totally sold on Rake, you still need to know that software like NetBeans expects to see a build.xml file, so it can interact with your project."
While Java developers can use Rake/Ant integration to make their lives easier, there are benefits to JRuby developers as well. Ant can be invoked from Rake, and Ant targets can be called as Rake tasks from within Rake - one can simply import an Ant buildfile to make its targets available to Rake as tasks. This allows Rake users to interact with existing Ant buildfiles and systems which depend on them.
"Ideally we'll cover all possible integration scenarios, and finally blur the lines between Rake and Ant," Nutter writes. "And we'll be able to move JRuby's build into Rake, which will make all of us very happy."
Sarah Howe Jul 06, 2015