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

17th
Mar 2016
wenhoujx
@wenhoujx
Mar 17 2016 05:00
hi @here is there a way to combine jrubyJar task and jar task to create just one jar ? Right now i am using assemble.dependsOn jrubyJar and it creates two jar. I don't want entirely override jar task, but update the jar. Thanks !
Christian Meier
@mkristian
Mar 17 2016 06:58
@raelik thanks - I found it: http://rubygems-proxy.torquebox.org/releases/rubygems/sprockets/2.9.4/sprockets-2.9.4.pom which comes already with this broken version range.
@wenhoujx JRubyJar extends Jar. so you should be able to do everything with JRubyJar - maybe that is what you already tried.
Luís Duarte
@driverpt
Mar 17 2016 11:50
@mkristian Logstash Plugins are JRuby gems. When logstash went to Elastic Co. they migrated it to JRuby and are ver slowly migrating everything to Java
Christian Meier
@mkristian
Mar 17 2016 11:52
@driverpt the problem is the jruby extension jar. the dependencies are nicely added to the maven classpath: http://rubygems-proxy.torquebox.org/releases/rubygems/logstash-core-event-java/2.3.0.snapshot1/logstash-core-event-java-2.3.0.snapshot1.pom
Luís Duarte
@driverpt
Mar 17 2016 11:55
this is why i love Groovy :P
Christian Meier
@mkristian
Mar 17 2016 11:56
both jruby-gradle and gem-maven-plugin (As you mentioned maven in jruby room) do install the gem inside their working directory. from there you need to find a way to add the extra jar from the unpacked gem to you classpath.
Luís Duarte
@driverpt
Mar 17 2016 11:58
jeezus........
Christian Meier
@mkristian
Mar 17 2016 12:40
but usually such jruby extension jars are not really useful outside a jruby runtime. not sure if I understand your undertaking
@driverpt -^
wenhoujx
@wenhoujx
Mar 17 2016 13:01
@mkristian without assemble.dependsOn jrubyJar build task create the wrong jar that contains only the java class. With assemble.dependsOn jrubyJar build task create two jar. I am wondering how to make build task create only one jar.
wenhoujx
@wenhoujx
Mar 17 2016 17:52
nvm, the example project (gist) you showed me only creates one jar with/without assemble.dependsOn jrubyJar. so it must be something with my other plugins.
wenhoujx
@wenhoujx
Mar 17 2016 19:04
In my ruby script, I use File::open() to open a relative path file, i pack everything into a executable jar. It has problems to find the file, the error looks like this:
[whou@whou-mbp gradle-ruby-integration]$ java -jar ./build/libs/gradle-ruby-integration-jruby.jar foo filename is foo Errno::ENOENT: No such file or directory - foo initialize at org/jruby/RubyFile.java:354 open at org/jruby/RubyIO.java:1122 run at uri:classloader:/app.rb:10 <top> at uri:classloader:/app.rb:19 require at org/jruby/RubyKernel.java:937 (root) at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1 <top> at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54 Exception in thread "main" org.jruby.embed.EvalFailedException: (ENOENT) No such file or directory - foo at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131) at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1307) at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1300) at Main.main(Main.java:9) Caused by: org.jruby.exceptions.RaiseException: (ENOENT) No such file or directory - foo at org.jruby.RubyFile.initialize(org/jruby/RubyFile.java:354) at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1122) at RUBY.run(uri:classloader:/app.rb:10) at RUBY.<top>(uri:classloader:/app.rb:19) at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:937) at RUBY.(root)(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1) at RUBY.<top>(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54)
as you can see in the log filename is foo, the file name foo is passed into the script,
puts "filename is #{filename}" file = File.open(filename, "r") puts "content of file is: #{file.read}"
but it cannot find file foo, which is in the same directory
but passing absolute path works
[whou@whou-mbp gradle-ruby-integration]$ java -jar ./build/libs/gradle-ruby-integration-jruby.jar /Volumes/git/gradle-ruby-integration/foo filename is /Volumes/git/gradle-ruby-integration/foo content of file is: Hello World
sorry, the newline is not shown in code paste
Christian Meier
@mkristian
Mar 17 2016 19:17
@wenhoujx is there a file .jrubydir on ROOT of your jar ? could you print out p Dir.pwd just before the File.open - it should give uri:classloader:/
relative file open works against the current working directory
wenhoujx
@wenhoujx
Mar 17 2016 19:38
let me try it
thanks
yes, it prints uri:classloader:/
wenhoujx
@wenhoujx
Mar 17 2016 19:44
it has a .jrubydir at the root, its content:
. com jni jnr jruby org tables Main.class app.rb Jars.lock gems specifications
wenhoujx
@wenhoujx
Mar 17 2016 19:53
what do i need to do in order to use relative path?
Blane Dabney
@raelik
Mar 17 2016 21:55
@wenhoujx specify -C $PWD when running jruby on the command line
if you do that, you may also need to specify JARS_LOCK=uri:classloader://Jars.lock
so in your case: JARS_LOCK=uri:classloader://Jars.lock java -jar ./build/libs/gradle-ruby-integration-jruby.jar -C $PWD foo
wenhoujx
@wenhoujx
Mar 17 2016 22:01
wow, thanks, will try. is this documented somewhere ?
Blane Dabney
@raelik
Mar 17 2016 22:02
Not that I know of, it should be though. Up until now, I think I may have been the only jruby-gradle user doing what you're trying to do.
i.e. package jruby and all your dependencies in a jar, and run it directly with java against a working tree of ruby files.
I didn't realize until now that that's what you were trying to do.
The way I solved your other issue is to add my java project as a subproject of my main jruby project, and have it publish it's jar artifact to a flat ivy repo inside the main project. Then the main project uses that jar as a dependency.
it means I have an odd catch-22 issue with versioning, but I get around that by building the subproject first and telling it to ignore the parent build.gradle.
the better way to do it would be to just separate the java project entirely, but in my case it has absolutely no use outside the parent project
wenhoujx
@wenhoujx
Mar 17 2016 22:07

`JARS_LOCK=uri:classloader://Jars.lock java -jar ./build/libs/gradle-ruby-integration-jruby.jar -C $PWD foo

uri:classloader:/
filename is -C
Errno::ENOENT: No such file or directory - -C
initialize at org/jruby/RubyFile.java:354`

java doesn't have a -C option.
you have a super cool profile picture .
:)
Blane Dabney
@raelik
Mar 17 2016 22:09
oh, so I was assuming that the main class in your jar was a jruby runner.
I'm guessing it's not :D
wenhoujx
@wenhoujx
Mar 17 2016 22:09
oh, your main class is an ruby script
Blane Dabney
@raelik
Mar 17 2016 22:09
my main class is basically jruby itself
-C is a ruby option
wenhoujx
@wenhoujx
Mar 17 2016 22:09
i see. I wanted it to be a java class so that my client can use it in their java program
i wonder if java has a similar option, it should be easier for me to find it now that I know it is the equivalent of Jruby -c option
Blane Dabney
@raelik
Mar 17 2016 22:11
right, I think what you'd have to do is use -Duser.dir=$PWD instead
dunno that you'd need JARS_LOCK
wenhoujx
@wenhoujx
Mar 17 2016 22:11
nice, let me try
wenhoujx
@wenhoujx
Mar 17 2016 22:20
about the other issue, do you happen to know an online example of it? i.e. subproject publish to a flat ivy repo and main project depend on it to build its own jar ?
Blane Dabney
@raelik
Mar 17 2016 22:20
No, just my own implementation which isn't a public project
wenhoujx
@wenhoujx
Mar 17 2016 22:22
ok, thank you for the hints and help! I think i can figure out the rest now.
Blane Dabney
@raelik
Mar 17 2016 22:22
so for the flat repo, in the main project I just added:
ivy { url 'lib/repo' }
wenhoujx
@wenhoujx
Mar 17 2016 22:22
oh, i didn't know the example is coming .
so you let subproject (java) to publish to lib/repo?
Blane Dabney
@raelik
Mar 17 2016 22:23
and then in the subproject, in uploadArchives, I added:
repositories { ivy { url '../lib/repo' } }
from within my subproject dir, I run: ../gradlew -u uploadArchives
the -u tells gradle to not search upward for a settings.gradle
that way it doesn't "know" that it's a subproject
wenhoujx
@wenhoujx
Mar 17 2016 22:25
make sense,
how do you make the main project jar task depends on the sub-rpoject jar in lib/repo?
Blane Dabney
@raelik
Mar 17 2016 22:26
in the main project, I have jrubyJar dependsOn ':subproject_name:uploadArchives'
but that only works if I'm not bumping the subproject's version #.
so I never rely on that
the dependency is declared like any other maven/ivy dependency
I just tested that -Duser.dir= myself, and it doesn't appear to change jRuby's CWD :/
wenhoujx
@wenhoujx
Mar 17 2016 22:29
do you need to add lib/repo to you main project's repository ?
Blane Dabney
@raelik
Mar 17 2016 22:29
I just put a .gitkeep in there
I don't commit any of the files in there normally, though in my case I have a non-public jar stored in there
normally I wouldn't though
stupid vertica.
wenhoujx
@wenhoujx
Mar 17 2016 22:30
vertica ? what does this has to do with vertica?
vertica reply on jruby ?
Blane Dabney
@raelik
Mar 17 2016 22:30
my project relates to Vertica
that's the non-public jar I have to keep in my repo, the vertica client library jar :P
you can download it from vertica, but they don't publish it to a maven repo or anything of the sort.
wenhoujx
@wenhoujx
Mar 17 2016 22:32
oh, i see. that's crazy
Blane Dabney
@raelik
Mar 17 2016 22:32
Well, they want it behind a "Accept our Licensing Terms" wall.
but yeah, annoying.
wenhoujx
@wenhoujx
Mar 17 2016 22:32
haha, i think that's a funny reason but as the same time i feel bad for you .
Blane Dabney
@raelik
Mar 17 2016 22:33
It's not a huge deal, the jar is only 731k
It's better than the alternative. All the pure ruby options for connecting to Vertica are complete crap.
with jRuby, I can use the jdbc driver and use whatever connection pool I like (I'm using HikariCP)
if I was running this on an app server, I'd just use whatever pool it had.
That would be insanely overkill for what this does though, so I'm not.
wenhoujx
@wenhoujx
Mar 17 2016 22:36
are other parts of your project java?
Blane Dabney
@raelik
Mar 17 2016 22:36
Just one tiny piece.
I wasn't satisfied with the CSV performance in ruby
wenhoujx
@wenhoujx
Mar 17 2016 22:37
then why do you have to use gradle ?
Blane Dabney
@raelik
Mar 17 2016 22:37
to be fair, the jruby team identified a massive performance bug there.
Well, it also depends on that vertica driver and on hikaricp
gradle was the best choice by far.
wenhoujx
@wenhoujx
Mar 17 2016 22:39
ok, good to know that. I gotta to go get some food, but thank you so much for your help, nice chatting with you :)
Blane Dabney
@raelik
Mar 17 2016 22:40
the small java piece I wrote takes a ResultSet and converts it to raw CSV (totally unparsed) and pipes that out as a chunked HTTP stream
I use rack.hijack to pass the raw socket from my webserver (Puma in this case) to Java.
I should write something up on that some day, it was a neat trick.