Skip to content

Instantly share code, notes, and snippets.

@grimrose
Created November 2, 2013 17:55
Show Gist options
  • Save grimrose/7281607 to your computer and use it in GitHub Desktop.
Save grimrose/7281607 to your computer and use it in GitHub Desktop.
GradleからJRubyを使う為に挑戦した結果
apply plugin: 'java'
repositories {
mavenCentral()
}
buildscript {
repositories { mavenCentral() }
dependencies { gradleApi() }
}
configurations {
jruby
}
dependencies {
jruby 'org.jruby:jruby-complete:1.7.5'
}
ext {
gemsDir = file('.jruby/gems')
}
import org.gradle.api.tasks.*
class JRubyTask extends DefaultTask {
def jRubyArgs = ["-S"]
@TaskAction
void process() {
List arguments = jRubyArgs.collect { it.toString() }.collect { it.contains('\'') ? it : it.tokenize() }.flatten()
project.logger.info "$arguments"
project.javaexec {
classpath = project.configurations.jruby
main = 'org.jruby.Main'
jvmArgs "-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dfile.encoding=UTF-8".tokenize()
environment 'GEM_PATH', project.ext.gemsDir
environment 'PATH', "${project.ext.gemsDir}/bin"
args arguments
}
}
}
task installBundler(type: JRubyTask) {
outputs.dir gemsDir
jRubyArgs << "gem install"
jRubyArgs << "-i $gemsDir"
jRubyArgs << "--no-rdoc"
jRubyArgs << "--no-ri"
jRubyArgs << "bundler"
doFirst {
gemsDir.mkdirs()
}
}
def ruby = hasProperty('ruby') ? ruby : ''
task runRubyCommand(type: JRubyTask) {
jRubyArgs = ["${ruby ? "-S " + ruby : "-v"}"]
}
task bundleInstall(type: JRubyTask) {
jRubyArgs << "bundle install"
jRubyArgs << "--path"
jRubyArgs << "$gemsDir"
}
task bundleUpdate(type: JRubyTask) {
jRubyArgs << "bundle update"
}
task bundleList(type: JRubyTask) {
jRubyArgs << "bundle list"
}
task rakeTasks(type: JRubyTask) {
jRubyArgs << "rake -T"
}
task runRSpec(type: JRubyTask) {
jRubyArgs << "rspec"
}
@grimrose
Copy link
Author

grimrose commented Nov 2, 2013

  • ローカルの環境で以下のコマンドを実行すると、jarに含まれているrake.rbが使われている模様。
$ gradle rRC -Pruby='gem which rake'
  • bundle exec rake spec はエラーとなってしまう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment