How can I use Ruby code in a buildr project?

How to use Ruby in a buildr project?

I used Ruby, JRuby, Java, and Clojure in a number of separate projects. I am currently working on a simulation application in standard Ruby, which I would like to try with the Clojure backend (I like the functional code), and the JRuby gui and test suite. I could also use, say, Scala, for the backend in another project in the future.

I think I'm going to give buildr (http://buildr.apache.org/) an attempt for my project, but I noticed that buildr does not seem to be configured to use JRuby code inside the project itself! This seems a little silly, as the tool is designed to unify common JVM languages ​​and is built in ruby.

Does anyone know how you would do this, apart from the issued cans in a separate, only ruby ​​project?

+5
source share
2 answers

You do not know exactly how you want to use your (J) Ruby code, so I will give one example of many possible approaches.

Let’s create a directory structure and put Java and Ruby files in it,

.
β”œβ”€β”€ buildfile
└── src
    └── main
        β”œβ”€β”€ java
        β”‚   └── Foo.java
        └── ruby
            └── app.rb

with the content Foo.javaas follows:

public class Foo {
  public int bar() {
    return 42;
  }
}

and a simple app.rbscript run,

puts "Foo.bar is #{Java::Foo.new.bar}"

Yours buildfilewill look something like this:

VERSION_NUMBER = "1.0.0"

repositories.remote << "http://www.ibiblio.org/maven2/"

JRUBY = "org.jruby:jruby-complete:jar:1.6.3"

define "ruby-example" do
  project.version = VERSION_NUMBER
  project.group = "org.example"

  run.with JRUBY
  run.using :main => ['org.jruby.Main', _(:src, :main, :ruby, "app.rb")]
end

(task rundocumented at http://buildr.apache.org/more_stuff.html#run )

and now you can run your application by typing

$ buildr run

and get the following output:

$ buildr run
(in /home/boisvert/tmp/ruby-example, development)
Foo.bar is 42
Completed in 1.884s
+7
+1

All Articles