2

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)

4
  • 1
    That may depend on how this JAVA_OPTS comes into life. According to the documentation, the standard Java launcher doesn’t support such a variable. Instead, there is JDK_JAVA_OPTIONS and when I set it to --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED, it works. Commented Jun 23, 2022 at 13:12
  • Thanks for the help but I am still getting errors. I tried JDK_JAVA_OPTIONS but still got the same error just with an extra line(edited the question with the exact command used and error message). And that JAVA_OPTS thing I actually tried by looking at some other stack overflow answer (stackoverflow.com/questions/57153917/…) Commented Jun 23, 2022 at 14:28
  • 1
    Ok. The “Picked up…” message clearly indicates that the option has been processed and there’s no follow-up error about an invalid option, so we have to assume that the option is active. Since this contradicts the fact that there’s still the IllegalAccessError, I make an educated guess: it’s a different JVM, i.e. javac has been started as a subprocess. Commented Jun 24, 2022 at 7:29
  • 1
    Hi, apologies for the delay. Here is what I was told: "Should be handled by this PR once it's merged github.com/sourcegraph/scip-java/pull/464" Commented Jul 12, 2022 at 20:07

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.