Are there any plans for JVM/Java support?
# sst
j
Are there any plans for JVM/Java support?
t
We add languages as they're requested. Is this something you'd like?
j
I just did a project with SST and TypeScript and was very impressed with the quick iteration workflow. Today we write Lambdas in Scala, and using AWS SAM, and our workflow does not have anything near the easy of use and iteration speed of what I’ve just experienced. Scala is fairly niche but if there’s Java support you can usually get things working for Scala pretty easy, so.
t
I'll create an issue for this. Frank is working on dotnet support right now but can probably move to Java after that. Long term we're looking to create a plugin model so people can easily specify how to compile and deploy any language they want which should make all of this more flexible
j
sounds awesome
f
Hey @Jimmy, a couple of questions on Java: 1. what commands are you running to build ur Java lambdas? 2. is it built inside a docker container? 3. what package managers are commonly used for Java? gradle? And which one r u using?
Hey @Jimmy, just circling back on this. Do you still need the Java runtime?
p
I believe @Jimmy is using gradle and buidling inside docker using sbt @Frank
j
sorry, was a bit laid back during vacation and was going to come back to this once I was at the office again 🙂
what commands are you running to build ur Java lambdas?
we currently only have scala lambdas, and it differ from Java up until the JAR is produced, then it’s handled just like any Java JAR. Like Pål says we use SBT to both build our Scala projects (though no gradle in there atm) and handle the package management for them. Builds are done within docker containers with the proper scala and sbt versions
we’re basically doing it like this https://github.com/fancellu/scala-sam-app
so in our build scripts we first do
sbt assembly
which produces a JAR
and then we do the same `sam package`as one does for Java
f
@Pål Brattberg @Jimmy Thanks guys for the details.
j
Np, ask away if you have any follow-up at any time
f
btw do you have scala and sbt installed on ur machine (outside of docker)?
j
Yes, for convenience when developing
We use intellij idea and it kinda assumes you have the tools locally (though I think it should be possible to run your compiler etc in docker). Docker performance on mac is pretty noticable for Java and .net development in my experience
When you have a big monolith, as one does, compiling in docker can be quite painful
But for microservices it can be tolerable
f
Yup that makes sense. I was asking b/c
sst start
tries to build your function code live as you are developing. So it’d be much faster to do it natively on ur machine.
And when you deploy, it can build inside the docker.
j
Yeah that makes a lot of sense
f
Btw, are the JARs OS dependent? As in a JAR built on Windows, can it be run on linux? (excuse my lack of Java knowledge 😔)
j
They're OS independent
f
So you are building in docker just to ensure consistent scala and sbt versions are used. Right?
j
Well unless you have some native bindings, but I think you usually distribute builds for "all" platforms along with the JAR then, normally
Yes, mostly because our CI/CD pipeline uses docker
f
Got it!
When do you need the Java support by timeline wise?
j
We're doing most of our new development as lambdas and we manage with the current setup, though "developer experience" and particularly iteration speed and unclear process around mocking/live resources/etc are the main complaints
So yeah it would be a fantastic improvement whenever it arrived 😄
We're up to our ears with compliance until October/November so we're not writing that many new lambdas atm at least
f
Sounds good! I think i’ve got most of the stuff required to get us started.
j
Cool!
f
I’m sure I will bug you again for some details later 🙂
j
How does the proxy lambda communicate with the locally running code?
Is it making http requests locally to the server running in c# etc?
I'm asking because thinking a bit on Scala which has some interesting solutions around "hot reloading"
f
It sends a websocket message to ur local with entire event and content;
sst start
then runs ur code with it; and sends the response back as a websocket message again.
j
I see, I'll give it a look and ponder the Scala application, thanks!
f
Yeah, let me know if the process can be improved by Scala’s hot reloading!
@Jimmy @Pål Brattberg Can
sbt package
be used instead of
sbt assembly
to build the JAR? I’m trying out the scala-sam-app.
sbt assembly
generated a 12MB JAR.
sbt package
generated a 16KB JAR, and also runs faster.
j
sbt package
only generates a JAR for your code, so any dependencies won’t be include, whereas
sbt assembly
createas a “fat jar” with all dependencies baked in. Since Lambda wants a (one) JAR for the JVM Lambda you need a fat jar, and otherwise you’d still need to include the other library JAR’s
perhaps it’s a smart optimization to have a lambda layer with the Scala standard library though, which would reduce the size
f
Thanks @Jimmy! May I ask: 1. how long does
sbt assembly
take for your project? 2. are all of your Lambdas in the same
sbt
project? Or 1
sbt
project per Lambda?
j
1. it takes a while, especially since it runs tests by default, 2 minutes on a project I just tried. For hot reloading the thing with scala is that one usually wants to keep sbt running and have it recompile on changes, so having an external watcher doing that is ideal. I guess you currently detect changes from outside and restart the language runtime? 2. one sbt project per “service”, which can be composed of multiple lambdas
since you proxy the lambda to the local code I guess doing an `assembly`etc might not be needed?
one can do `sbt ~assembly`which will do a hot recompile & assembly on a source code change, but the assembly still takes 20s for me (compilation 4s)
f
Yeah,
sst start
currently restarts the language runtime. If we were to keep
sbt
running, do we need to have multiple
sbt
processes running, 1 for each service?
j
good question, I assume you do if we’re not doing something custom
f
@Jimmy @Pål Brattberg hey guys, I have an early version with Scala + sbt support. It works well on Mac/Linux, but has an issue on Window. If you guys are on windows, I’m hoping for some help 😔
So this is what I’m running to build the jar file on Linux:
Copy code
sbt 'set assemblyOutputPath in assembly := new File("/path/to/project/build/index.jar")' "set test in assembly := {}" assembly
On windows, I can’t seem to be able to escape the
"
or the
)
inorder to set the
assemblyOuputPath
. I tried this:
Copy code
sbt "set assemblyOutputPath in assembly := new File(""/path/to/project/build/index.jar"")" "set test in assembly := {}" assembly
And I’m getting the error:
Copy code
set was unexpected at this time.
Any ideas guys?
j
Hey Franke that sounds amazing, I’ll set aside some time to check it out today or tonight. From the windows message it appears set is evaluated by the shell (regular windows cmd.exe), not sure why at first glance though.
f
Thanks @Jimmy. I can cut a canary release for you to try it out after getting around this issue.
t
i guess I could be interested in this as well, due to certain level of obession we have with Kotlin & Java within our developers 😄 (kotlin folks are particullary obsessed with their language of love) 😄 did you guys get anywhere with this first version?