1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
# jruby maven plugin
the plugin is modeled after [jruby-gradle](http://jruby-gradle.github.io/) and uses the old jruby maven plugins under the hood but it needs jruby-1.7.19 or newer (including jruby-9.0.0.0 serie).
even if the plugin depends on the old jruby-maven-plugins BUT has a different version.
## general command line switches
to see the java/jruby command the plugin is executing use (for example with the verify goal)
```mvn verify -Djruby.verbose```
to quickly pick another jruby version use
```mvn verify -Djruby.version=1.7.20```
or to display some help
```mvn jruby9:help -Ddetail```
## jruby exec
it installs all the declared gems from the dependencies section as well the plugin dependencies. all jars are loaded with JRuby via ```require``` which loads them in to the JRubyClassLoader.
the complete pom for the samples below is in [src/it/jrubyExecExample/pom.xml](src/it/jrubyExecExample/pom.xml)
the gem-artifacts are coming from the torquebox rubygems proxy
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
to use these gems within the depenencies of the plugin you need
<pluginRepositories>
<pluginRepository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</pluginRepository>
</pluginRepositories>
the jar and gem artifacts for the JRuby application can be declared in the main dependencies section
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>leafy-rack</artifactId>
<version>0.4.0</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>minitest</artifactId>
<version>5.7.0</version>
<type>gem</type>
<scope>test</scope>
</dependency>
</dependencies>
these artifacts can have different scope BUT the exec goal will use ALL scopes.
the plugin declaration
<build>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>jruby9-maven-plugin</artifactId>
<executions>
<execution>
<id>simple</id>
<phase>validate</phase>
<goals><goal>exec</goal></goals>
<configuration>
<jrubyVersion>9.0.3.0</jrubyVersion>
<script>p 'hello world'</script>
</configuration>
</execution>
<execution>
<id>rspec</id>
<phase>test</phase>
<goals><goal>exec</goal></goals>
<configuration>
<command>rspec</command>
</configuration>
</execution>
<execution>
<id>test file</id>
<phase>test</phase>
<goals><goal>exec</goal></goals>
<configuration>
<file>test.rb</file>
</configuration>
</execution>
</executions>
now the plugin uses rspec and needs rpsec gems installed via
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rspec</artifactId>
<version>3.3.0</version>
<type>gem</type>
</dependency>
the main dependencies section does use leafy-rack and to see some of its logging you need a slf4j logger for the tests
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
|