How to configure Rubygems for Maven?

So I’ve been toying around with the RubyGems Maven Support in JRuby
1.6.0.RC1
(http://www.engineyard.com/blog/2011/jruby-1-6-0-rc1-released/),
and I’m getting weird errors trying to install anything. From what it
looks
like, it doesn’t know to go to a maven repository to get the :

PS C:\mydocs> jruby -S gem install joda-time:joda-time -V
GET http://gems.rubyforge.org/latest_specs.4.8.gz
302 Found
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
ERROR: Could not find a valid gem ‘joda-time:joda-time’ (>= 0) in any
repository

Is there anything I need to set in my ~/.gemrc to get maven to integrate
with JRuby? My .gemrc looks like this currently:

PS C:\mydocs> jruby -S gem env
RubyGems Environment:

  • RUBYGEMS VERSION: 1.4.2
  • RUBY VERSION: 1.8.7 (2011-01-10 patchlevel 330) [java]
  • INSTALLATION DIRECTORY: C:/jruby-1.6.0.RC1/lib/ruby/gems/1.8
  • RUBY EXECUTABLE: C:/jruby-1.6.0.RC1/bin/jruby.exe
  • EXECUTABLE DIRECTORY: C:/jruby-1.6.0.RC1/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • universal-java-1.6
  • GEM PATHS:
    • C:/jruby-1.6.0.RC1/lib/ruby/gems/1.8
    • C:/mydocs/.gem/jruby/1.8
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
    • “install” => “–env-shebang”
    • “update” => “–env-shebang”
    • :sources => [“http://gems.rubyforge.org/”]
  • REMOTE SOURCES:

We have a corporate Nexus repository that we have our settings.xml
mirroring
all requests to, which works great for our Java projects, but I don’t
know
how to configure JRubyGems to use it when requesting a maven dependency.
Any tips, steps, or things I am probably just not doing to get Maven to
play nice with JRuby?

-Nick

On Jan 14, 2011, at 09:32 , Nick K. wrote:

We have a corporate Nexus repository that we have our settings.xml mirroring all
requests to, which works great for our Java projects, but I don’t know how to
configure JRubyGems to use it when requesting a maven dependency. Any tips,
steps, or things I am probably just not doing to get Maven to play nice with
JRuby?

First you’ll need to either have Maven 3 installed (and the ‘mvn’
executable on your path) or install the pre-release ruby-maven gem (gem
install ruby-maven --pre).

The base support assumes only the Maven central repository. To use a
different repository, use a mvn:// URL, which is just a normal http://
Maven repository with mvn: used as the scheme instead, to mark it
differently from a Rubygems source. You can either add the repository as
a remembered source (gem sources add mvn://host/path) or simply use it
on the gem install command-line with the --source mvn://host/path
option.

Note that this use of custom repositories is subject to change and we’d
appreciate your feedback.

/Nick

Try again with “gem install --debug” for more information including
backtrace. Oddly, it looks like it expects to create the gemspec in a
temp directory but then it couldn’t find it.

/Nick

This looks like an improvement, but not nearly as verbose as doing a gem
install, so I don’t know how to get any more information on what is
causing
it:

PS C:\mydocs> jruby -S gem install joda-time:joda-time -V --source
mvn://mavenrepo:8081/nexus/content/groups/public
ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/temp/gemify2107458040932456836/joda-time.joda-time-1.4.0-java.gemspec

BTW, I do have Maven 3.0.2 installed and have set the appropriate
variables
(M2, M2_HOME). This is on Windows XP SP3, FWIW.

looks like problem with the windows absolute path.

the ‘map’ error is a bug but only for the debug output.

regards, Kristian

Could the error be because JRuby is passing ‘/’ paths instead of ‘’ to
Maven and Maven doesn’t/can’t interpret it properly?

C:>jruby -S gem install joda-time:joda-time -V --source mvn://
mavenrepo.alliant-energy.com:8081/nexus/content/groups/public--no-http-proxy
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/temp/gemify4288182487619828364/joda-time.joda-time-1.4.0-java.gemspec

For instance:

C:>type /?
Displays the contents of a text file or files.

TYPE [drive:][path]filename

C:>type
c:/temp/gemify4288182487619828364/joda-time.joda-time-1.4.0-java.gemspec
The syntax of the command is incorrect.

-Nick

That’s better. Here’s a more useful list of errors:

PS C:\mydocs> jruby -S gem install joda-time:joda-time -V --source
mvn://
mavenrepo.alliant-energy.com:8081/nexus/content/groups/public --debug
Exception LoadError' at org/jruby/RubyKernel.java:1041 - no such file to load -- openssl ExceptionGem::LoadError’ at
C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems.rb:812 - Could not
find
RubyGem test-unit (>= 0)

Using Maven install at C:\Java\maven/bin
maven goals:
de.saumya.mojo:gemify-maven-plugin:0.22.0:versions
system properties:
ERROR: While executing gem … (NoMethodError)
undefined method `map’ for #Java::JavaUtil::Properties:0xc4b626

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:256:in
`execute’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:269:in
`get_versions’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:83:in
`maven_find_matching_with_errors’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:41:in
`find_matching_with_errors’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:71:in
`fetch_with_errors’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:108:in
`find_gems_with_sources’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:212:in
`find_spec_by_name_and_version’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:244:in
`install’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:120:in
execute' org/jruby/RubyArray.java:1671:ineach’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:115:in
execute' C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/command.rb:278:ininvoke’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:134:in
`process_args’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:104:in
`run’

C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:63:in
run' C:/jruby-1.6.0.RC1/bin/gem:21:infile
Exception `Gem::SystemExitException’ at
C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb:310

Exiting RubyGems with exit_code 1

However, I have jruby-openssl (0.7.2 with bouncy-castle-java
(1.5.0145.2)
) installed, so I don’t know why that would be happening.

— Also, to make things confusing, the exceptions above say that it
couldn’t load openssl or test-unit, but I can do that through IRB just
fine:

PS C:\mydocs> jruby -S irb
irb(main):001:0> require ‘openssl’
=> true
irb(main):002:0> require ‘test/unit’
=> true
irb(main):003:0> exit
Loaded suite jirb
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

The error does look like it can’t find the file, but it’s there:

PS C:> jruby -S gem install joda-time:joda-time -V --source mvn://
mavenrepo.alliant-energy.com:8081/nexus/content/groups/public
ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/temp/gemify5584659624050685778/joda-time.joda-time-1.4.0-java.gemspec
PS C:> cd .\temp\gemify5584659624050685778
PS C:\temp\gemify5584659624050685778> dir

Directory: C:\temp\gemify5584659624050685778

Mode LastWriteTime Length Name


-a— 01/14/2011 1:17 PM 873
joda-time.joda-time-1.4.0-java.gemspec

On Sat, Jan 15, 2011 at 10:35 PM, Nick K. [email protected] wrote:

ERROR: While executing gem … (Errno::ENOENT)
No such file or directory -
c:/temp/gemify4288182487619828364/joda-time.joda-time-1.4.0-java.gemspec

this looks like a ruby error message

the piece of code which produces something wrong is most likely
https://github.com/jruby/rubygems/blob/jruby-rubygems_1_4_2/lib/rubygems/maven_gemify.rb#L290

maven creates the gemspec which seems to work and rubygems needs to
parse it.

yes it looks like “/” versus “” could be the problem.

regards Kristian

PS I guess that is the first time I would like to have a windows box
at hand but I do not have so I can help only with “good” words :wink:

So I’m trying to figure out what is causing the path errors, but I’m not
having much luck. I did find something else that I was curious about:

Here’s a snippet of the failing install for joda-time:

Using Maven install at C:\Java\apache-maven-3.0.2/bin
maven goals:
de.saumya.mojo:gemify-maven-plugin:0.22.0:versions
system properties:
gemify.tempDir => c:\temp\gemify6445382149565106971
gemify.gemname => joda-time.joda-time
versions: [“1.4.0”, “1.5.2”, “1.6.0”, “1.6.1”, “1.6.2\r”]
maven goals:
de.saumya.mojo:gemify-maven-plugin:0.22.0:gemify
system properties:
gemify.tempDir => c:\temp\gemify6445382149565106971
gemify.version => 1.4.0
gemify.gemname => joda-time.joda-time
gemify.onlySpecs => true

Why is it picking 1.4.0 for the joda-time version, and not 1.6.1 or
1.6.2?

I’m glad I can help. I use Windows at work and JRuby is both the best
option as well as the one that works well with my development efforts
(mostly Java).

I also noticed this line:
https://github.com/jruby/rubygems/blob/jruby-rubygems_1_4_2/lib/rubygems/maven_gemify.rb#L170

https://github.com/jruby/rubygems/blob/jruby-rubygems_1_4_2/lib/rubygems/maven_gemify.rb#L170Which
coincidentally triggered something I just read on EngineYard by Thomas
Enebo: http://www.engineyard.com/blog/2011/jruby-on-windows/#more-5743
where
he mentions using
Pathnamehttp://ruby-doc.org/stdlib/libdoc/pathname/rdoc/index.html
instead
of filename =~ /^// to determine absolute paths.

-Nick

the joda-time works with me and the versions I see are only
[1.6.1, 1.6.2]
and rubygems takes the latest versions.

when you look at the output

system properties:
gemify.tempDir => c:\temp\gemify6445382149565106971
gemify.version => 1.4.0
gemify.gemname => joda-time.joda-time
gemify.onlySpecs => true
then the last line says onlySpecs=true
rubygems (if I understand it right) just gets the specs for all
available versions and then decides for the “right” version.

you see “1.6.2\r” which is not a valid version string and will fail
rubygems install.

the version list for joda-time is too short so there is indeed
something going on here.

regards, Kristian