Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
maven plugin to handle rubygems in a maven way. including support for rspec, rails, cucumber, rake, etc
Java Ruby HTML JavaScript Other

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
gem-maven-plugin
jruby-maven-plugin
rails-maven-archetype
rails2-maven-plugin
rails3-maven-plugin
rspec-maven-plugin
.gitignore
History.txt
README.textile
archetype-catalog.xml
eclipse-code-style.xml
license.txt
pom.xml

README.textile

maven plugins for jruby

my problem with maven vs. gem

both project try to solve the same problems. I just wrote a gem for jruby only, now I need to include some java code as a jar file and I depend on 3rd party jars. what shall I do ? pack them all up with the gem. but then I loose all dependency info from my jars and I cannot share them and I might run into version conflicts later since the gem packed jar file is just a file like any ruby file.

maybe these plugins helps projects where ruby and java lives side by side. maybe you have a java project and need some rubygems for your ruby scripting. or the other way around you have a ruby project and want to use java libraries with a lot of dependencies. have look at these plugins they might help you to manage the java world and ruby world in the same manner.

how to use it

there are plenty of integrations test in src/it of each plugin. so the best is to look through those examples.

nice plugin prefixes

add following to your settings.xml (see also http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html)

<settings>
  <pluginGroups>
    <pluginGroup>de.saumya.mojo</pluginGroup>
  </pluginGroups>
  . . . 
h3. pom.xml config

important is to declare the rubygems repository whenever you have gem artifacts as dependencies:

 <repositories>
    <repository>
      <id>rubygems</id>
      <releases>
        <updatePolicy>never</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <url>http://rubygems.org/gems</url>
      <layout>gem</layout>
    </repository>
  </repositories>

here there are a few things to mention: update-policy is set to ‘never’ to tell core maven to not do it, the gem plugin will take of this on daily manner. the checksum-policy is set to ‘ignore’ since there are no checksum files – anyways you will see some error messages with the checksum which can be safely ignored. the gem layout works only with maven3 (maven2 produces some error of not finding the layout with hint ‘gem’)

jruby-maven-plugin, rails2-maven-plugin, rails3-maven-plugin, rspec-maven-plugin

for example the jruby plugin declaration looks like this:

  <build>
    <plugins>
      . . . .
      <plugin>
        <groupId>de.saumya.mojo</groupId>
        <artifactId>rails3-maven-plugin</artifactId>
        <version>${jruby.plugins.version}</version>
      </plugin>
      . . . .

more help you get with

  • mvn ruby:help
  • mvn rails2:help
  • mvn rails3:help
  • mvn rspec:help

the prefix is ruby since there is already a jruby plugin on codehaus with the prefix jruby.

gem-maven-plugin

  <build>
    <plugins>
      . . . .
      <plugin>
        <groupId>de.saumya.mojo</groupId>
        <artifactId>gem-maven-plugin</artifactId>
        <version>${jruby.plugins.version}</version>
        <extensions>true</extensions>
      </plugin>
      . . . .

please not the extensions set to true – only with this setting the gem plugin can manage the gem artifacts properly

more help you get with

mvn gem:help

common parameters for all goals

please use ruby:help, gem:help, rspec:help, rails2:help and rails3:help to get more info about the parameters for a specific goal.

the first name is the system property which can be set either via the commandline (-Dmy.property.name=value) or via the properties section in the pom.xml. and the second name is the name for configuration part of the plugin.

  • jruby.fork (fork) – default: true
  • jruby.verbose (verbose) – default: false
  • jruby.home (home) – default: none
  • jruby.version (version) – default: taken from dependency or 1.5.0
  • jruby.launchMemory (launchMemory) – default: 384m
  • jruby.gem.home (gemHome) – default: target/rubygems
  • jruby.gem.path (gemPath) – default: target/rubygems
  • (launchDirectory) – default: current-directory when there is no pom, or basedir

common parameters for all goals from gem, rpec and rails plugins

  • “offline command line switch -o” (offline) – default: false
  • gem.includeOpenSSL (includeOpenSSL) – default: true
  • gem.forceVersion (forceVersion) – default: false
  • gem.useTransitiveDependencies (useTransitiveDependencies) – default: false

any goal has the properties ‘jruby.version’ and ‘jruby.fork’. you can set via the command line

common parameters for all goals from rails2/rails3 plugins

  • args (args) – default: none
  • rails.dir (dir) – default: src/main/rails or basedir
  • rails.env (env) – default: none (but rails defaults to development)

rubygems

the default behaviour is to fork jruby which allows to use a custom gem home/path wiith a default location of target/rubygems. there maven will install all gems which were declared as dependency (including transitive gem depedencies). important: this does not work if you use the embedded jruby (fork=false)!

after a mvn clean you can be sure that there is just one version for given gem present in target/rubygems. maven also resolves the version needed which might be different from what you get if you use rubygems or bundler. you can always use an explicit dependency to select a specific version of a particular gem.

note: with rubygems any version with an alphabet is a “prerelease”. for maven this is not the case and it treats all versions in similarthe same manner. to rectify this is a pending issue.

rails-maven-archetype

suppose you have already a rails-2.3.5 application inside a myapp directory. have a terminal open in the parent directory of this application and execute following command:

mvn archetype:generate -DarchetypeCatalog=http://github.com/mkristian/jruby-maven-plugins/raw/master/archetype-catalog.xml

  • there you have only one choice – so choose it :-)
  • for the groupId just use “rails” or whatever you desire
  • the artifactId is important and must match your application directory – i.e. myapp
  • the version and package just take the default

the archetype is stupid and uses rails version 2.3.5 as default and sqlite3 as database and it does not matter what the rails application actually uses. in case you need something else do as follow:

mvn archetype:generate -DarchetypeCatalog=http://github.com/mkristian/jruby-maven-plugins/raw/master/archetype-catalog.xml -Drails.version=3.0.0.beta3 -Ddatabase=mysql

for some little more info what you can do with this start the server (as usual or) with

mvn rails2:server

and open the browser at http://localhost:3000/maven.html

Something went wrong with that request. Please try again.