## 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 ***"
end


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:

     <plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>rake-maven-plugin</artifactId>
<version>1.0.0-rc3</version>


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

       <executions>
<execution>
<id>run-spec</id>
<phase>verify</phase>
<goals>
<goal>rake</goal>
</goals>
<configuration>
<args>do_that_thing</args>
</configuration>
</execution>
</executions>
</plugin>


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:

  <repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>


You can then add the dependency to the rake gem:

  <dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rake</artifactId>
<version>10.1.0</version>
<type>gem</type>
</dependency>
</dependencies>


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


## Comment

 Name Remember Email Website Message Textile help