IntelliJ IDEA not indexing GraalVM libraries

1.1k views Asked by At

I'm kinda new to this GraalVM stuff so please help me. I am using IntelliJ IDEA as my IDE and Gradle as my standard build system. I'm using the inbuilt GraalVM JDK (it's based on Java 11) for all of my projects. So, my problem is when I try to import the org.graalvm.polyglot or any such package it draws a squiggly line under the import which signifies that IntelliJ IDEA doesn't recognize the package and hasn't indexed it. But when I run it with gradle or any method, the imported packages work. The IDE's autocomplete doesn't work. It is kinda irritating to type out the whole name of the class and method just like one would while programming in Notepad. I have seen some tutorials for this which suggested that I add the graal-sdk.jar as a dependency but the jar file wasn't to be found in the Java 11 version of GraalVM. I even added the whole lib folder to IntelliJ's Libraries section in Project Structure. All of these did not work out. Could anybody help me out with this?

1

There are 1 answers

5
Oleg Šelajev On BEST ANSWER

One way to make IDEA recognise the graal-sdk.jar classes is to add it to your dependencies via the build tool. The jar is available on Maven Central: https://mvnrepository.com/artifact/org.graalvm.sdk/graal-sdk/20.2.0

so adding it to the dependencies with Maven scope: provided will make IDEA to index it and provide content assist, etc. but it won't be used or packaged, cause it's provided.

For Gradle I think it's the compileOnly.

Edit: For completeness, on JDK11 things are packaged in jmod files: https://docs.oracle.com/javase/9/tools/jmod.htm#JSWOR-GUID-0A0BDFF6-BE34-461B-86EF-AAC9A555E2AE

And maybe you can convince IDE to look at them. I think it's the $GRAALVM_HOME/jmods/org.graalvm.sdk.jmod