Java: java.lang.foreign.* is a preview API and is disabled by default. (use --enable-preview to enable preview APIs)

I'm trying to compile the elasticsearch-main source code with java version 21 in intellij idea but are getting this error.

Tried already to add --enable-preview to the compiler vm options but no success.

Welcome!

Could you try with java23?

If I want to change the java version, I need to adjust the gradle file. It is now set to version 21.

The short answer is don't.

Use IntelliJ to write code, but compile Elasticsearch using Gradle, and then run tests using gradle or the gradle runner inside intelliJ,

Is it possible to configure the build for podman instead of docker?

Maybe.

We need a docker command that behaves like the docker CLI, but we don't really care whether that's backed by docker or by podman.

You can probably get away with docker compatibility mode in podman.