Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gradle concept - Supporting JRuby + Gems
// This is just a concept - this code does not exist !!
// I have placed it here in order to facilitate discussion
// let's assume that we have specified the lcoation of the jruby
// plugin in buildscript {} block
apply plugin : 'jruby'
repositories {
jcenter()
}
// ===============================================
// Specify jruby version
// We have two options
// ===============================================
// #1 - Use a version string. This will search the
// repositories for 'org.ruby:jruby:${jRubyVersion}
jRubyVersion = '1.7.12'
// #2 - Use the standard dependency notation
// The 'jruby' plugin will provide compile, testCompile
// etc. if they have not already been provided by the
// 'java' plugin.
// Some additional thoughts required here. WHat if we
// only need jruby during build-time, but not afterwards?
//
dependencies {
compile 'org.ruby:jruby:1.7.12'
}
// ===============================================
// What about adding gems?
// ===============================================
// 'jruby' plugin will provide the 'gemXXX' extensions
// Gems will be downloaded to ~/.gradle/cache/jruby (or similar)
dependencies {
// Gem is needed for compilation and will be packaged up as part
// of artefact
// NOTE the lack of groupID as gems do not have that concept AFAIK
gemCompile 'erubis:2.7.0'
// Gem is only needed during testing (thus will not be packaged )
gemTestCompile 'erubis:2.7.0'
// Gem is only needed for runtime and needs to be packaged as part
// of artefact
gemRunTime 'erubis:2.7.0'
// Gem is needed as part of build, but not later on.
// Only passed to jrubyexec and JRubyExec
gemExec 'erubus:2.7.0'
}
// ================================================
// What about adding repositories for finding gems?
// ================================================
// Obviously these will be needed :)
//
repositories {
rubygems {
name 'rubygems-release'
url 'http://rubygems-proxy.torquebox.org/releases'
}
rubygems {
name 'my-rubygems-on-bintray'
url 'http://dl.bintray.com/myBintrayName/myBintrayGemRepo'
}
}
// ================================================
// What if I need to execute a ruby script ?
// ================================================
// Let's provide a task for that as well as a
// project extension.
// Both cases will use the jruby provided via
// dependencies
task runMyRubyScript( type : JRubyExec ) {
script '/path/to/my/script.rb'
args '-x', '-y', '-z'
// rest of config follows much of JavaExec task
}
task myCustomTaskAlsoNeedsSomeRubyLove << {
jrubyexec {
// similar to task
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment