Configuring CircleCI for JRuby

Ershad Kunnakkadan

By Ershad Kunnakkadan

on August 1, 2016

Recently we worked with a client where we had to run a part of their multi-threaded code in JRuby for performance reasons. They have been using CircleCI with MRI for running tests. In this post I will explain how we configured CircleCI to run the same tests using both JRuby and MRI.

CircleCI uses circle.yml file for configuration. Before configuring JRuby, this is how it looked like:

2  ruby:
3    version: 2.1.5
6  pre:
7    - ./
8  cache_directories:
9    - "~/vendor/bundle"
12  override:
13    - ? bundle exec rspec --format progress --format documentation --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/app.xml
14      : parallel: true
15        pwd: app
16        files:
17          - spec/**/*_spec.rb

Specify the JDK version

We need to specify a JDK version before using JRuby.

2  java:
3    version: openjdk7

Install proper dependencies

We needed to use JRuby but the version of JRuby that came with Ubuntu 12.04 image of CircleCI was different. We added rvm install command as follows to install specific version that we wanted. Also we can configure any script (like bundle install) that needs to run before running tests.

2  pre:
3    - rvm install jruby-
4    - ./
6  cache_directories:
7    - "~/vendor/bundle"

Configure JRuby

We used rvm-exec to set JRuby for running tests for this particular component in the test section. Otherwise by default it picks up MRI.

2  override:
3    - ? rvm-exec jruby- bash -c "bundle exec rspec --format progress --format documentation --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/app_jruby.xml"
4      : parallel: true
5        pwd: app
6        files:
7          - spec/**/*_spec.rb

Improving test runs on JRuby

Once we started running tests with JRuby, we observed it was taking comparatively slower to finish all tests. Most of the time was spent in starting the JVM. We made it faster by setting --dev parameter in JRUBY_OPTS environment variable. This parameter improves JRuby boot time and it shaved more than a minute time for us.

2  environment:
3    JRUBY_OPTS: "--dev"

Here is the final circle.yml file:

1# circle.yml
4  ruby:
5    version: 2.1.5
7  java:
8    version: openjdk7
10  environment:
11    JRUBY_OPTS: "--dev"
14  pre:
15    - rvm install jruby-
16    - ./
18  cache_directories:
19    - "~/vendor/bundle"
22  override:
23    - ? rvm-exec jruby- bash -c "bundle exec rspec --format progress --format documentation --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/app_jruby.xml"
24      : parallel: true
25        pwd: app
26        files:
27          - spec/**/*_spec.rb
29    - ? bundle exec rspec --format progress --format documentation --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/app_mri.xml
30      : parallel: true
31        pwd: app
32        files:
33          - spec/**/*_spec.rb

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.