If you ask yourself why IntelliJ shows many things red, no worrie IntelliJ isn't updated to support these language features.
So back to topic. Simply build it using gradle.
./gradlew clean build
java --enable-preview -jar build/libs/java-22-test-1.0-SNAPSHOT.jar