Call Rake from Maven

When it comes to interacting between Maven and Ruby, the TorqueBox JRuby Maven plugins are the best solutions. Mostly maintained by Christian (who has also done a lot of work converting JRuby to Maven), they work quite well, albeit lacking in documentation.

As part of these plugins, the rake-maven-plugin allows you to call Rake tasks in a project, which can be useful if the build tool of your comapny is based on Java, but your project is Ruby-based (and you don’t want to use JRuby). To illustrate its use, we’ll use a very straightforward Rakefile:

task :do_that_thing do
  puts " *** RAKE RUNNING ***"

It has a unique task, do_that_thing, that we’ll call from Maven. In the pom, you need to add the rake-maven-plugin:


We are now going to define its execution, and tie it to the verify lifecycle step (you can choose what step you want):


The goal we are calling on the Rake plugin is rake, and the name of the Rake task is passed in args. As we are using Rake, we need to define a gem dependency to rake. To do so, you first need to add the rubygems Maven repo provided by TorqueBox:


You can then add the dependency to the rake gem:


Running mvn verify will then execute the Rake task.

The full example can be found on my GitHub repo, rake-maven-example.

To get more details about the Rake maven plugin (or any plugin at all in general), the help plugin comes, as usual, quite handy:

mvn help:describe -Dplugin=de.saumya.mojo:rake-maven-plugin:1.0.0-rc3 -Ddetail