rubyrakejrubygemfilerakefile

Rakefiles and Gemfiles


So I understand the basic concepts of a Rakefile and a Gemfile (rakefiles are basically just dependency lists and shell commands to compile and link the application while gemfiles specify gem version dependencies for an application), but how should I use these in unison? More specifically: I have a project for a project at my Uni that I am going to use Ruby 1.8.7 and JRuby 1.7 on with a set of gems I have installed through RVM on my local machine.

The problem is is that my application must compile and run without error on the computer lab at my Uni and the Uni doesn't have JRuby on these machines. I can install onto my shell account, and I did that with JRuby to get my application to compile but now I am required to type in the full path to the jruby installation to compile my project (something like /usr/home/usrname/blah/jruby-1.7.0) and I feel that is annoying and I would like something simpler (and learn at the same time).

The machines at my Uni have Rake installed and I was wondering if it would be possible for me to set up a rake file to do the call to JRuby and all the gems I need (specified in the gemfile with their respective installation paths). Is this possible? Or am I thinking of rakefiles and gemfiles in the wrong way?


Solution

  • The Rakefile is used to set up dependencies for running Rake within the context of your project. You have correctly described the purpose of the Gemfile.

    Rake is an independent program from JRuby. It will be included in the bin folder of your JRuby install. By the time you reach your Rakefile, you are already in the context of the wrong version of Rake (the one included with the regular Ruby install).

    I think what you are looking for is just a modification to your path. Include your JRuby bin folder in your path, and that will allow you to specify which version of Rake you want to use.

    For the JRuby version:

    jruby -S rake your:task
    

    Or just the regular Ruby version:

    rake your:task