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

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,