Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created May 25, 2019
Embed
What would you like to do?
A quick example pre-compiling JRuby before stuffing it into a .jar file.
plugins {
id 'java'
id "com.github.jruby-gradle.base" version "1.7.0"
id "com.github.jruby-gradle.jar" version "1.7.0"
}
import com.github.jrubygradle.JRubyExec
dependencies {
jrubyJar "rubygems:state_machines:0.5.0"
compile "org.jruby:jruby-complete:${jruby.defaultVersion}"
}
sourceSets {
main {
java {
srcDirs = ['src/generated/java']
}
}
}
task compileRuby(type: JRubyExec) {
jrubyArgs '-S', 'jrubyc', '--java', '-t', "${projectDir}/src/generated/java"
script 'main.rb'
doFirst {
mkdir "${projectDir}/src/generated/java"
}
}
task prepareCompiledRuby {
dependsOn 'compileRuby', 'compileJava'
}
jrubyJar {
dependsOn 'prepareCompiledRuby'
mainClass 'com.github.jrubygradle.sandbox.Main'
from "${buildDir}/classes/java/main"
into('assets') {
from 'assets'
}
archiveName "${rootProject.name}.jar"
}
#!/usr/bin/env ruby
require 'java'
java_package 'com.github.jrubygradle.sandbox'
class Main
java_signature 'void main(String[] args)'
def self.main(args)
puts 'Hello World'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment