salesforce/bazel-vscode-java

Trivial Bazel 6.4.0 example project (without `rules_jvm_external`) fails to open

vorburger opened this issue · 2 comments

When I open code java_one/ in https://github.com/vorburger/LearningBazel it fails like this:

Command failed: bazel --output_base=/tmp/07d06c474e5b9ccb01482f273e2b80b3 query ...:* --output=package
Loading: 0 packages loaded
ERROR: error loading package under directory '': error loading package 'bazel-java-one/external/bazel_tools/tools/android': Label '//tools/python:private/defs.bzl' is invalid because 'tools/python' is not a package; perhaps you meant to put the colon here: '//:tools/python/private/defs.bzl'?
Loading: 1 packages loaded
    currently loading: bazel-java-one/external/remote_java_tools ... (4 packages)

This does not even use rules_jvm_external like #73.

@guw

guw commented

I get a different error:
image

It looks like the LS detects the project Java configuration as 1.8.

ERROR: error loading package under directory '': error loading package 'bazel-java-one/external/bazel_tools/tools/android': Label '//tools/python:private/defs.bzl' is invalid because 'tools/python' is not a package; perhaps you meant to put the colon here: '//:tools/python/private/defs.bzl'?

OK so that is actually from BazelBuild.vscode-bazel and not (this project) sfdc.bazel-vscode-java - how confusing! 🤣 I've now raised #78 to amend the Troubleshooting guide with a tip about that. I've opened bazelbuild/vscode-bazel#328 about that; let's ignore it, here.

I get a different error:
It looks like the LS detects the project Java configuration as 1.8.

I (now, after "clearing the fog") see that as well, copy/paste from .log:

!ENTRY org.eclipse.jdt.ls.core 4 0 2024-01-05 12:08:37.565
!MESSAGE Error occured while building workspace. Details: 
 message: Preview features enabled at an invalid source release level 1.8, preview can be enabled only at source level 21; code: 2098258; resource: /home/vorburger/git/github.com/vorburger/LearningBazel/java-one/src/main/java/ch/vorburger/learningbazel/Main.java;

The Problems view also has:

  • The compiler compliance specified is 1.8 but a JRE 17 is used

  • Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment.

Do you suspect that is the real problem here, and in #73? I'm not entirely sure what real problems, if any, this actual causes? I have (vague) memories of having seen this back in my Eclipse days, and things were still working.

The Main.java editor seems fine, and navigation into JDK classes work.

I have attempted to hack / workaround it by changing Java Version 1.8 with the Java: Configure Java Runtime command, but can't figure out how to Save it; it keeps "reverting"?!

Adding the following to .bazelrc (in vorburger/LearningBazel@2a98503):

# https://bazel.build/docs/bazel-and-java#java-versions
build --java_language_version=11
build --tool_java_language_version=11

# https://bazel.build/docs/user-manual#java_runtime_version
build --java_runtime_version=remotejdk_11
build --tool_java_runtime_version=remotejdk_11

seems to make the 2 messages above in Problems go away, and (predictably) changes the error in .log to:

!ENTRY org.eclipse.jdt.ls.core 4 0 2024-01-05 12:39:25.798
!MESSAGE Error occured while building workspace. Details: 
 message: Preview features enabled at an invalid source release level 11, preview can be enabled only at source level 21; code: 2098258; resource: /home/vorburger/git/github.com/vorburger/LearningBazel/java-one/src/main/java/ch/vorburger/learningbazel/Main.java;

Which is perhaps still slightly surprising - why/what wants "Preview features enabled" as "preview can be enabled only at source level 21" - in a project that's declared as Java 11 only - but be that as it may. I've raised PR #79 to add documentation about that.

Clicking Run in the Main.java editor just fails though - but perhaps we should treat that as a separate new problem, see #80.

Let me close this, as the original problem is "solved" (it does not "fail to open", actually). I'll further pursue #75 instead next.