Can I specify that a gem is for JRuby only?

Adam Murray's Avatar

Adam Murray

12 Jun, 2011 12:02 AM

Is there something I can put in my .gemspec to indicate that the gem will only work with JRuby? I'm working on a gem that wraps Java libraries, and so requires JRuby. I couldn't find any information on this. It seems like you can only specific platform and (numeric) ruby version.

I'll of course document this requirement, but it would be nice if the gem simply fails to install with a reasonable error (or is not even available for install) with MRI Ruby. If there's nothing I can do in .gemspec, maybe I can do something else to make the installation fail?

  1. Support Staff 1 Posted by Nick Quaranto on 12 Jun, 2011 05:16 PM

    Nick Quaranto's Avatar

    Specifying the java platform usually does it, and if you a build a gem from JRuby it should do that automatically. You could also set the platform specifically:

  2. 2 Posted by Adam Murray on 13 Jun, 2011 05:31 PM

    Adam Murray's Avatar

    Ok, it sounds like I should simply add:

    platform = "java"

    to my gemspec. I'll try that. Thanks!

  3. 3 Posted by Adam Murray on 16 Jun, 2011 07:58 AM

    Adam Murray's Avatar

    spec.platform = "java" in the gemspec seems to simply append "java" to the end of my gem name. It still installs into MRI ruby.

    Someone suggested I use gem's (native) extension mechanism to write a script that would fail if not running under JRuby. But I can't seem to get this to work. I always get the error "cannot build native extension" even when my ext script does nothing.

    I also tried building with both jgem and normal gem, but it didn't seem to make a difference. Although it's not clear to me if the local behavior when testing these things will be the same as when installing from I only used the gem command "for real" so far. Next time I'll try to remember to build and push via jgem and see if that helps.

    Maybe there's a bug report or enhancement request in here somewhere, but I guess it's not that big of a deal. I suppose if people can't RTFM or figure out a gem that starts with "j" and ends with "java" is intended for JRuby, that's not really not my problem ;)

  4. 4 Posted by Luis Lavena on 19 Jun, 2011 03:23 PM

    Luis Lavena's Avatar

    Hello, let us know if you need anything else.

    Closing this now.


  5. Luis Lavena closed this discussion on 19 Jun, 2011 03:23 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac