Run loom demo on IDEA

479 Views Asked by At

I want to run loom's demo, I downloaded jdk18-loom from http://jdk.java.net/loom/, and downloaded the latest version of IDEA:

enter image description here

No matter I choose X or 17-preview, the program cannot run, reports: Executors.newVirtualThreadPerTaskExecutor() Is an API in a preview feature.

How to solve it?

2

There are 2 best solutions below

1
On

What I had to do step by step.

Update to 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, got 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 you run configuration 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 resovle this I had to switch the gradle VM to java 17, wati for it to build and them back to 19

0
On

I was able to run loom project by JosePaumard
There are multiple steps as of now to make it work.

  1. Download suitable java version with all the feature you wanted to try.
  2. If it is using any build tools, make sure it is compatible with java version you are trying.
  3. build tool settings needs to be updated with JVM arguments e.g. for maven export MAVEN_OPTS="--enable-preview --add-modules=jdk.incubator.concurrent --add-exports=java.base/jdk.internal.vm=ALL-UNNAMED" or in pom.xml file.
  4. set JAVA_HOME to proper JAVA version
  5. Intellij-Idea configs: Change JAVA_compiler configurations and each class runConfigurations
  6. Change Project level SDK version and set language level to preview features you need to test.
  7. Update to latest Intellij-idea IDE, verified with 2023.1 version

Ref


Latest Java 21 support for following frameworks and Kotlin

  • SpringBoot 3.2
  • Kotlin 1.9.20(but this has issue with kapt annotation processor), so better use 1.9.21
  • Gradle version: 8.5
  • Latest intellij-idea IDE version or after 2023.1