I've noticed Micronaut and Quarkus have gradle plu...
# http4k
a
I've noticed Micronaut and Quarkus have gradle plugins that make it easier to build a native image. It might be nice if http4k had the same thing. What other nice-to-haves could a plugin provide? Or is that more of a framework thing? I suppose any native image plugin that would work for http4k would work for any other stack, after all.
j
But, what plugin do you need? Last time I checked it was 6 lines of gradle... https://github.com/time4tea/http4k-functional/blob/main/build.gradle.kts A lot of these frameworks need complicated pligins because of all the reflection - it makes it difficult for graal to know what is required, so must be configured...
a
Maybe that is the only plugin I need 🤷. I'm new to graal.
j
I suspect the only thing you need is the graal plugin... by all means copy from the build file above, it's 1 year old, so probably some version numbers changed, but it was fully working for a simple http4k app.
The above has two targets, one for jib one for graal... they are independent
a
I followed this guide which has you use the docker cli to build the image. Perhaps the graal plugin makes it unnecessary if it can hook into a dockerized builder easily. https://www.http4k.org/guide/tutorials/going_native_with_graal_on_aws_lambda/
j
Hmm.
./gradlew nativeCompile
Should be enough...
a
I'll keep that in my pocket for next time. Thanks for the tip
👍 1
Do you know how to configure it to use a dockerized builder?
d
The native compile plugin will work for your local platform - handy if you're in a ci pipeline where you can control the platform you're building on. If you want a Graal lambda then afaik it will need to run on a Linux base. That docker image doesn't use gradle - so you can just point it to a jar file and it outputs the correct zip file
I don't know if you can target a different platform directly from the gradle plugin? I doubt it tbh.
a
Not sure if I'm explaining myself properly. Basically, in micronaut and quarkus, the gradle task to build the native image can be configured to run on a docker image
Copy code
tasks.named<io.micronaut.gradle.docker.NativeImageDockerfile>("dockerfileNative") {
    baseImage = "amazonlinux:2"
    jdkVersion = "21"
}
So it essentially does what the http4k graal tutorial teaches you to do, but with more options on builder image (e.g. AL 2023). I'm not entirely sure how it loads the graal runtime into a blank AL2 container, but let's say it's magic for now. Now with the standard graal plugin for gradle, it appears that it will only use your local graal jvm, and target your host platform. No option to use docker. What I'm hoping for is a generic plugin to do what micronaut does. Not only does this mean I don't have to have the Graal toolchain installed, but it also means I can target other environments easily. For example, a native image built on AL2 will not work on an AL2023 runtime.
d
ah - that's good information - I didn't know that they were incompatible! But you actually should be able to override the version of the docker image by tweaking the command line.
a
Ah yes, I see you can override the Amazon Linux version. I think that can only be set during docker build? The AL version incompatibility is something I noticed while building for micronaut. The native image was built on AL 2023 but the lambda runtime was set to AL2. I got an error when the runtime couldn't find a supported version of GLIBC. I think there's a graal option to statically link dependencies, but ideally you would keep your binary as small as possible on Lambda.