You are previewing Maven: The Definitive Guide.

Maven: The Definitive Guide

Cover of Maven: The Definitive Guide by Sonatype Company Published by O'Reilly Media, Inc.
O'Reilly logo

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, and for more information about JRuby, see

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> ...

The best content for your career. Discover unlimited learning on demand for around $1/day.