Unfortunately, even the latest early-access versions of IntelliJ often do not yet support early-access versions of Java.
For example, I am trying to use Intellij 2022.1.1 Preview (Ultimate Edition) with the experimental build of Project Loom based on early-access Java 19. Installing JDK generally works with IntelliJ.
But now I want to use the Loom-specific features. When I invoke a method new in to this experimental Java 19, I get this error from compiler:
java: newVirtualThreadPerTaskExecutor() is a preview API and is disabled by default.
(use --enable-preview to enable preview APIs)
My first thought is to set the Language level fields on the File > Project Structure > Project Settings > Project and … Modules panels. But apparently IntelliJ does not offer any menu items for a (Preview) mode for this early-access Java 19.
👉 Is there some way to make IntelliJ utilize the new preview API?
I know the error message's suggestion of --enable-preview is meant to be a flag applied somewhere. But I don't know where.
What I had to do step by step.
Update the IDE to the latest version
Download a JVM with loom
Add the loom JDK to the IDE
Set it both to project and to your build tool
Set enable preview and source to 19 as compiler options to do this, go to prefs -> compiler -> java compiler, uncheck the --release option thing and add the following compiler args for specific project global
--enable-preview --source 19
these are directly passed to javac when it compiles
Set the enable preview on your run configuration and add --enable-preview as a JVM option (if you don't see it click 'Modify options')
You should be good to go, I faced a bug where sometimes Gradle complained that it is not compatible with my JVM, to resolve this I had to switch the Gradle VM to java 17, wait for it to build, and then back to 19
EDIT:
Maven is a better option for experimenting with non-LTS versions. With maven I had zero problems, Gradle has some weird ifs here and there that throw errors if they "Don't support" certain Java-Gradle version combo, even though they use maven beneath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With