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

5th
Apr 2016
Schalk W. Cronjé
@ysb33r
Apr 05 2016 09:50
Keep an eye on this Gradle Forum thread - https://discuss.gradle.org/t/add-rubygems-to-gradle/15955
Riccardo Tacconi
@rtacconi
Apr 05 2016 10:14
Hello I am using this script https://github.com/c9katayama/aws-lambda-jruby/blob/master/build.gradle to build an AWS lambda function with JRuby. The build script creates a zip file with this dirs/files "AWSLambdaJRuby.class lib main.rb stdlib". Do you have an idea how I could add a gem to the project by using Gradle? I am completely new to gradle.
Christian Meier
@mkristian
Apr 05 2016 10:18
@rtacconi so do you want to pack your compiled code and jruby itself into one jar file ?
Riccardo Tacconi
@rtacconi
Apr 05 2016 10:26
From the AWS Java tutorial I see I should compile my gems in a jar and put it into lib dir
Christian Meier
@mkristian
Apr 05 2016 10:28
as far I understand it - yes. and use initScript library() which packs your gems into the jar so jruby will find them if the jar is on the classpath
Riccardo Tacconi
@rtacconi
Apr 05 2016 10:50
@mkristian thank you I managed to update to this https://gist.github.com/rtacconi/2df474e32d90df77ec2f6b9735a6672d and now I see the script is downloading the gems. However the gem is not created and added to the lib directory. I guess I need another step to do that.
jrubyJar {
// tell the plugin to pack a runnable jar (no bootstrap script)
initScript library()
where's the jar created with that?
Christian Meier
@mkristian
Apr 05 2016 11:42
@rtacconi the jar should be in ./build/libs and has a postfix -jruby.jar
Riccardo Tacconi
@rtacconi
Apr 05 2016 11:44
yes found it and I added compile files('build/libs/aws-lambda-jruby.jar'). However on AWS lambda it is not still found, not sure why. Thank you
Christian Meier
@mkristian
Apr 05 2016 11:45
any error message ?
Christian Meier
@mkristian
Apr 05 2016 11:47
can you check that the jar with the gems indeed have them. unzip -l jar-with-gems.jar to see if the gems are inside the ./gems directory and there is a ./specifications directory as well
Riccardo Tacconi
@rtacconi
Apr 05 2016 12:00
the jar is the content of src/main/resources. There is not any jar with the gems, only one jar in build/libs
Christian Meier
@mkristian
Apr 05 2016 12:01
I see. ./gradlew jrubyJar should build you the jar with the gems
Riccardo Tacconi
@rtacconi
Apr 05 2016 12:03

:jrubyJar (Thread[main,5,main]) started.
:jrubyJar FAILED
:jrubyJar (Thread[main,5,main]) completed. Took 0.035 secs.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem was found with the configuration of task ':jrubyJar'.

    No value has been specified for property 'mainClass'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

it seems it is trying to build an executable jar not a lib
Christian Meier
@mkristian
Apr 05 2016 12:04
are you using the latest jruby-gradle-jar-plugin ? older versions did have problems with the library bits. just to be on the safe side
classpath "com.github.jruby-gradle:jruby-gradle-jar-plugin:1.0.1"
Christian Meier
@mkristian
Apr 05 2016 12:07
1.2.0 is the latest version
bbl
Riccardo Tacconi
@rtacconi
Apr 05 2016 12:10
yes now I have two jars :-)
Schalk W. Cronjé
@ysb33r
Apr 05 2016 12:11
problem solved?
Riccardo Tacconi
@rtacconi
Apr 05 2016 12:12
I am testing it every time I have to upload 20MB to S3 than update the lambda function
no, the new jar has another jar which has some Java classes, Jetty.something.class JRuby.something.class
Schalk W. Cronjé
@ysb33r
Apr 05 2016 12:20
why is this line in your script? compile files('lib/jruby.jar’)
Riccardo Tacconi
@rtacconi
Apr 05 2016 12:22
because I am using this example https://github.com/c9katayama/aws-lambda-jruby which has lib/jruby.jar
In the end the project is composed by few jars from AWS, a Java handler which calls a jruby script and jruby itself. I am using gradle for the first time
Christian Meier
@mkristian
Apr 05 2016 13:00
@rtacconi this https://github.com/c9katayama/aws-lambda-jruby is not a nice example of how to use jruby. question: do you want to use this example and just add some gems to your jar ? the lib/jruby.jar and src/main/resources/stdlib is just bad. this can be improved. regarding the gems inside a jar. it looks like that you just zip up all java libraries and give it to AWS, this means you need the jar with gems packed into your zip file. so I will give it a few cycles on fork of this repo
Riccardo Tacconi
@rtacconi
Apr 05 2016 13:06
I can agree with you, there are few things I quite not see the reason they are done that way. This is the official documentation http://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html and I think that github project started from that example in the AWS documentation. Thank you, any help would be appreciated. There are not good examples on how to write an AWS lambda function with JRuby and it would help a lot to bring Ruby on lambda.
Schalk W. Cronjé
@ysb33r
Apr 05 2016 13:08
@rtacconi in @mkristian you have one the best guys that I know in the ruby+jruby+java world to help.
Christian Meier
@mkristian
Apr 05 2016 13:09
@ysb33r @rtacconi the gradle bits still needs more practice :)
Riccardo Tacconi
@rtacconi
Apr 05 2016 13:25
:-)
this is my branch which does create a jar with gems and packs it into the zip and improves the embedded jruby bots as well
I can not test it :(
so I depend on you !
if we get this into a working state I am happily submit a PR to the original repo
Riccardo Tacconi
@rtacconi
Apr 05 2016 13:47
OK I will test it ASAP and let you know it looks good :-)
Christian Meier
@mkristian
Apr 05 2016 13:48
the main.rb script there does not use those gems, so you will not see any gem not found related errors in any case. but if the zip works as it then I am pretty sure the gems work as well
Riccardo Tacconi
@rtacconi
Apr 05 2016 14:11
I get a timeout error when I run a test. The zip file looks ok. I will have a look later at the moment I can't do it. I will let you know. Thank you again.
Christian Meier
@mkristian
Apr 05 2016 14:12
please - I have to go as well right now. any error message will help
Riccardo Tacconi
@rtacconi
Apr 05 2016 14:13
{
"errorMessage": "2016-04-05T14:10:09.665Z 122f7ab3-fb38-11e5-8b84-4bef225cae26 Task timed out after 15.00 seconds"
}
Christian Meier
@mkristian
Apr 05 2016 14:13
hmm that is less then expected :(
Riccardo Tacconi
@rtacconi
Apr 05 2016 14:14
the test sends a json hash and the lambda function returns the hash, but it seems it is not responding
AWS lambda sucks with feedback :-(
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:11
I tried the other branch, better-jruby-handling, same result. It times out.
Christian Meier
@mkristian
Apr 05 2016 17:14
the master branch I did not change - but before saw this java stacktrace org.jruby.embed.EvalFailedException so this mean something worked before, i.e. you got jruby executed.
I am not sure what this main.rb script is doing from this repo you are testing
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:15
I think it prints a YAML version of the incoming JSON. It is printed to the AWS lambda logs.

I changed it with require 'json'
require 'aws-sdk'

return $lambda_arg.to_json

Christian Meier
@mkristian
Apr 05 2016 17:17
is there some incoming json ? or does something hanging waiting for some incoming data - just wildly speculating
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:17
it seems, as you said, main.rb is not executed
from the AWS console I can test the lambda function
it just sends some JSON data and it prints the logs
a sort of echo server demo
parameters are here $lambda_arg
I know a bit of Java I could have a look how it works, but basically in the lambda function I have to specify a handler, with is the name of the Java class which implements the AWS lambda interface
Christian Meier
@mkristian
Apr 05 2016 17:21
first the data gets logged into the AWS-context - do you see this log ?
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:22
with your change I just see the timeout error
Christian Meier
@mkristian
Apr 05 2016 17:23
and with master it works ? or do you see the log there ?
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:24
to be correct it is the output of the function, not the logs (https://docs.aws.amazon.com/lambda/latest/dg/java-programming-model.html). No I do not. Only the original version works. In both cases I get a time out
I see you modified src/main/java/AWSLambdaJRuby.java
+import org.jruby.embed.IsolatedScriptingContainer; and more... may be the issue is there?
Christian Meier
@mkristian
Apr 05 2016 17:27
maybe.
that is why I asked if you can see this line executed context.getLogger().log(arg);
Riccardo Tacconi
@rtacconi
Apr 05 2016 17:45
no any code is executed, at least from what I see in the AWS console. I checked your change, you changed the way to load the standard library and you are using IsolatedScriptingContainer, but you did not change the handler method nor the AWSLambdaJRuby class, show it should be called. May be is a packaging problem. One annoying issue with AWS lambda is that we cannot zip the directory containing the files, but the files must be zipped, and with my near null knowledge of Gradle, I am not sure if I can check that.
I have to go for now thanks again
rtyler @rtyler wakes up
Schalk W. Cronjé
@ysb33r
Apr 05 2016 18:11
@rtacconi I’ll help you inthe morning with the Gradle zip'ing