These are chat archives for jruby-gradle/jruby-gradle-plugin

14th
Mar 2016
Schalk W. Cronjé
@ysb33r
Mar 14 2016 11:56
@wenhoujx Can I help?
wenhoujx
@wenhoujx
Mar 14 2016 14:21
Hello, @ysb33r thanks for offering help, my project has a ruby CLI application that takes various argument and run inside a terminal.
My client wants to use this tool but only if it is wrapped in java.
so I am using jruby-gradle plugin to pull and put together all the gems and builds a jar,
any idea how to use load the ruby classes from the jar inside JAVA context?
Thanks !
Christian Meier
@mkristian
Mar 14 2016 14:25
@wenhoujx when you are already inside a java application, then you can use org.jruby.embed.IsolatedScriptingContainer to spawn a jruby runtime. on this scripting-container you can execute ruby code
is that what you want to do ?
wenhoujx
@wenhoujx
Mar 14 2016 14:28
I was trying to compile the class ahead of time, but I think your approach is much easier and lead to the same performance.
Christian Meier
@mkristian
Mar 14 2016 14:29
ahead compilation of ruby classes is more an obfuscating feature and the compiled classes do load slower then ruby version of it as each ruby method turns out to be inside its own class
wenhoujx
@wenhoujx
Mar 14 2016 14:35
hmm, thanks for explaining. so I know how to to build ruby script + its gems into a jar using jruby-gradle-plugin, I know how to call that jar inside a JRuby runtime, but how do i wrap everything altogether into one single jar?
Christian Meier
@mkristian
Mar 14 2016 14:40
initScript library()
inside your jar plugin config
wenhoujx
@wenhoujx
Mar 14 2016 14:44

I have tried that config, but get this error : * What went wrong:
A problem was found with the configuration of task ':example-project:jrubyJar'.

No value has been specified for property 'mainClass'.

Christian Meier
@mkristian
Mar 14 2016 14:45
do you use the latest version ? I suppose you do. yes, there were problems, got fixed. maybe not released. not sure.
wenhoujx
@wenhoujx
Mar 14 2016 14:46
oh, I am not using the latest version, I got that error from the example-project i checked out, which is using 1.0.1
thanks, will try with 1.2.1
Christian Meier
@mkristian
Mar 14 2016 14:46
just let us know if it is still broken !
wenhoujx
@wenhoujx
Mar 14 2016 14:48
it is working thanks so much!
Christian Meier
@mkristian
Mar 14 2016 14:48
cool - happy to hear
Schalk W. Cronjé
@ysb33r
Mar 14 2016 15:34
Cool. I just got to read thie messages but you got help from the expert I see.
wenhoujx
@wenhoujx
Mar 14 2016 15:38
@ysb33r thank you just the same.
rtyler @rtyler wakes up
wenhoujx
@wenhoujx
Mar 14 2016 15:50
As a proof of concept, I modified the project in presentations/jruby-gradle-java-powertools/example-project. I run the main.rb inside a ScriptingContainer from the Demo.java, it seems that ruby cannot find the dependency: Exception in thread "main" org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- colorize
wenhoujx
@wenhoujx
Mar 14 2016 15:58
what should i set the Jruby ScriptingContainer loadpath to, when using this plugin?
Christian Meier
@mkristian
Mar 14 2016 16:00
did you take the IsolatedScriptingContainer which sets the load path to root of the jar, and sets the GEM_PATH, etc as well. the ScriptingContainer will not find the gems out of the box. colorize sounds like an embedded gem - can this be ?
wenhoujx
@wenhoujx
Mar 14 2016 16:02
dependencies { jrubyExec 'rubygems:rspec:2.99.0+' // <1> gems 'rubygems:colorize:0.7.7' // <2> jrubyJar 'org.slf4j:slf4j-simple:1.7.12' // <3> compile 'org.jruby:jruby-complete:9.0.5.0' }
colorize is inside the build.gradle.
Christian Meier
@mkristian
Mar 14 2016 16:03
so IsolatedScriptingContainer should work as is.
wenhoujx
@wenhoujx
Mar 14 2016 16:03
out of box?
Christian Meier
@mkristian
Mar 14 2016 16:04
without setting any load or gem path
wenhoujx
@wenhoujx
Mar 14 2016 16:04
hmm, let me try again
thanks
Christian Meier
@mkristian
Mar 14 2016 16:05
@rtyler @ysb33r we should add such a test case to our testsuite using a scripting-container to run the code
R. Tyler Croy
@rtyler
Mar 14 2016 16:07
I'm open to that :)
wenhoujx
@wenhoujx
Mar 14 2016 18:02
still couldn't figure out, can i get some help ? :worried:
Christian Meier
@mkristian
Mar 14 2016 18:04
@wenhoujx today is busy on my side. will gist you something tomorrow
wenhoujx
@wenhoujx
Mar 14 2016 18:17
cool, thanks! I just need an example about how to run ruby script from java and use this plugin to take care the deps.
Blane Dabney
@raelik
Mar 14 2016 19:06
Looks like there might be an issue with gemspec parsing and dependencies with negated versions
for instance, sprockets (one of the rails gems) v2.x has a dependency on tilt that looks like ["~> 1.1", "!= 1.3.0"]
They did that because tilt doesn't have a 1.3.0 release, just 1.3 and 1.3.1+
R. Tyler Croy
@rtyler
Mar 14 2016 19:09
huh
I've never seen that before, interesting
Blane Dabney
@raelik
Mar 14 2016 19:10
yeah, what happens is gradle tries to resolve that as an actual dependency
on 1.3.0
well, ok, it says there is no overlap for [1.3,1.3.99999] and (=1.3.0,1.99999]
maybe it's just ignoring that and it's ruby-maven that's having the problem?
Christian Meier
@mkristian
Mar 14 2016 22:33
(=1.3.0,1.99999] this one looks wrong, there should be no = inside brackets