Created
May 25, 2019 18:18
-
-
Save rtyler/7635e9c110548882504729ff7445ed0b to your computer and use it in GitHub Desktop.
A quick example pre-compiling JRuby before stuffing it into a .jar file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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