Writing Plugins in JRuby

Ruby is an object-oriented scripting language that provides a rich set of facilities for metaprogramming and reflection. Ruby’s reliance on closures and blocks make for a programming style that is both compact and powerful. Although Ruby has been around since 1993, most people came to know Ruby after it was made popular by a Ruby-based web framework known as Ruby on Rails. JRuby is a Ruby interpreter written in Java. For more information about the Ruby language, see http://www.ruby-lang.org/, and for more information about JRuby, see http://jruby.codehaus.org/.

Creating a JRuby Plugin

To create a Maven plugin using JRuby, you need to have a pom.xml and a single Mojo implemented in Ruby. To get started, create a project directory named firstruby-maven-plugin. Place the pom.xml shown in Example 18-4 in this directory.

Example 18-4. POM for a JRuby Maven plugin

<project> <modelVersion>4.0.0</modelVersion> <groupId>org.sonatype.mavenbook.plugins</groupId> <artifactId>firstruby-maven-plugin</artifactId> <name>Example Ruby Mojo - firstruby-maven-plugin</name> <packaging>maven-plugin</packaging> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>jruby-maven-plugin</artifactId> <version>1.0-beta-4</version> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-plugin-plugin</artifactId> <version>2.4</version> <dependencies> <dependency> <groupId>org.codehaus.mojo</groupId> ...

Get Maven: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.