Indexing a java 17 project using sourcegraph's scip-java

Viewed 166

I am following the method given at: https://sourcegraph.github.io/scip-java/docs/getting-started.html

From the root directory of a project I am running : docker run -v $(pwd):/home/gradle sourcegraph/scip-java:latest scip-java index --build-tool=gradle

But on running this command I am getting the following errors:

Exception in thread "main" java.lang.IllegalAccessError: class com.sourcegraph.semanticdb_javac.SemanticdbPlugin (in unnamed module @0x1794d431) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x1794d431

In the getting started guide it says that Java 17 requires custom --add-exports (https://sourcegraph.github.io/scip-java/docs/getting-started.html#java)

For Java 17 and newer versions, the following JVM options are required:

--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

I have tried various ways to add these options but have not been able to do it correctly (Following are some things I tried and the corresponding error I got)

docker run -e JAVA_OPTS="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -v $(pwd):/home/gradle sourcegraph/scip-java:latest scip-java index --build-tool=gradle

Using JVM version 'temurin:17' Unrecognized option: --add-exports Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unrecognized option: --add-exports Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

docker run -e JAVA_OPTS="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -v $(pwd):/home/gradle sourcegraph/scip-java:latest scip-java index --build-tool=gradle

Using JVM version 'temurin:17' Error: Could not find or load main class jdk.compiler.com.sun.tools.javac.api=ALL-UNNAMED Error: Could not find or load main class jdk.compiler.com.sun.tools.javac.api=ALL-UNNAMED

I don't have very basic experience with Java programming, and currently, my main objective is to index a repository and test the Sourcegraph precise code intelligence tool. (I am trying to index: https://github.com/spring-projects/spring-framework)

How can I add these JVM options?

Edit:

I tried using Holdger's way(from the comments) but still getting the same errors.

docker run -e JDK_JAVA_OPTIONS="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" -v $(pwd):/home/gradle sourcegraph/scip-java:latest scip-java index --build-tool=gradle

The error message I got was(It is just the part where the task fails):

NOTE: Picked up JDK_JAVA_OPTIONS: --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED Exception in thread "main" java.lang.IllegalAccessError: class com.sourcegraph.semanticdb_javac.SemanticdbPlugin (in unnamed module @0x1794d431) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x1794d431 at com.sourcegraph.semanticdb_javac.SemanticdbPlugin.init(SemanticdbPlugin.java:19) at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugin(BasicJavacTask.java:255) at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugins(BasicJavacTask.java:229) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:292) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176) at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64) at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

1 Answers

I left a comment but didn't get a response. Hopefully, this works.

This should be fixed with this PR: https://github.com/sourcegraph/scip-java/pull/464

Try re-running

$ docker run -v $(pwd):/home/gradle sourcegraph/scip-java:latest scip-java index --build-tool=gradle
Related