Before you begin, set up your maven workspace to download from the http://propellors.net/maven-repo repository. Also, be certain that you have ruby 1.8 or greater installed, and either the ruby binary in your environment PATH, or the environment variable RUBY_HOME pointing to your base installation directory.
Next, run the rubyarchetype plugin. This is similar to the archetype plugin in the maven project, however, is specifically designed to generate ruby layouts (archetype mostly supports java project layouts).
mvn rubyarchetype:create -DgroupId=test -DartifactId=rubyplugin
This will download and install the maven-rubyarchetype-plugin and execute it, creating a new project for you named rubyplugin.
rubyplugin
|-- pom.xml
`-- src
`-- main
`-- scripts
`-- my_mojo.rbLook at the my_mojo.rb file. It is the ruby mojo that the goal mymojo will be created from. Now change to the base of the new rubyplugin directory, and install the generated plugin.
cd rubyplugin mvn install
Now you have a Ruby Mojo in your repository! Go ahead and run the mymojo goal.
mvn test:rubyplugin:1.0-SNAPSHOT:mymojo
You should see the following, with the default value in the param:
[INFO] [rubyplugin:mymojo] [INFO] This is my param: 'hello!'
That's it! You can create a test project that configures the param to be any value you wish, and it will be displayed instead of the default 'hello!'. I hope everything worked well. Please note that this has yet to be tested extensively (just WinXPSP2), so testing on multiple OS's would be great! In any case, if you find any errors, please contact me. Thanks! (Please do not email me with general ruby or maven questions. However, do not hesitate to contact me about this project!)
Ruby has quickly grown from an academic curiosity to a script-writer's dream for many reasons. But the following are some of the more obvious ones:
But I don't need to sell you on Ruby. Chances are you know and love it; that's why you are here.
Maven has been around for at least a couple years, like Ruby (and potatoes), it has been flourishing underground. But there have been a couple issues stopping Maven from reaching its full potential:
In my opinion, that is all. Maven 2 on the other hand, is simple, componentized, extensible. All plugins are written in Java. Although a huge step up from Jelly, Java is ill-suited for operations generally required in build systems. Namely: file manipulations, parsing, document generation. It is a wonderful core, but no one wants to write, compile, test and package a Maven Java class (dubbed a Mojo) containing akwards Java parsing code to do something simple like extracting file annotations. Enter Ruby Mojo support.
Unfortunately, Maven does not come with every task you could ever want done already available from ibiblio. Fortunately, the developers have added hooks into the very core of Maven 2, making extension of the build-lifecycle relatively painless. My goal is to make it even more painless by adding support for a language that is more suited for the majority of tasks one will encounter when extending their build system with whatever hacks the developer likes. Ruby is such a language. You can download the code here, or better yet, use it correctly by including the projects into your plugin. Note that there are special installation instructions in this alpha phase. I have yet to figure out how to make usage of this extension passive.
It is still very much in alpha phase. So much so, that the todo list may seem shocking, but its not that bad:
Unless you followed the quickstart guide, you need to download and install the code. Later, this will be on ibiblio with the other kids.
And add this to your ruby plugin POM (an archetype is to come):
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-script-ruby</artifactId>
<version>1.0-alpha-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<configuration>
<prefix>ruby</prefix>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-plugin-tools-ruby</artifactId>
<version>1.0-alpha-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>Use the plugin like any Java plugin, defining configuration properties in the same way with one notable exception: All properties are currently Strings. This is something that I will fix in the future, but for the time being, all plugins used written in Ruby must contain only parameters of strings. This is not to say that you cannot pass in a string, and convert it to a File, or an Array, or anything else.
A good simple plugin example is in the SVN repository, under maven-rubytest-plugins. A test which uses the plugin is also under SVN, called maven-rubytest. The first contains a script with a two ruby mojos in src/main/scripts
# @goal test
class RubyTest < Mojo
# @parameter default-value="nothing"
def prop=( prop ); @prop = prop; end
def execute
print "The following String was passed to prop: '#{@prop}'"
end
end
run_mojo RubyTestNote the run_mojo method at the end. It is what populates and executes the execute method, as well as sends any output to the system, prints messages and errors to the Mojo log. run_mojo must be called for the Mojo to work, and takes a parameter of the class (not a string, the class). prop= is the property method that will be populated.
To get the sample running, all you should need to do its check it out of SVN, cd to the base dir, run:
mvn install
Then, in the directory of the maven-rubytest project, run:
mvn rubytest1:test
And you'll get a nice little message:
[INFO] [rubytest1:test] [INFO] The following String was passed to prop: 'This is a property I set'
Ooohh.... doesn't that feel good? :) A better test is in the same project pair name 'todo'. To use it type the following under the maven-rubytest project:
mvn rubytest1:todo
And you'll get the message:
[INFO] [rubytest1:todo] [INFO] Test.java, line 7: Finish this method!