Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vorburger opened this issue Jan 5, 2024 · 2 comments

Comments

@vorburger
Copy link
Contributor

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
Copy link
Collaborator

guw commented Jan 5, 2024

I get a different error:
image

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

vorburger added a commit to vorburger/bazel-vscode-java that referenced this issue Jan 5, 2024
…release level 11, preview can be enabled only at source level 21' to Troubleshooting doc

Related to salesforce#74.
@vorburger
Copy link
Contributor Author

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 bazel-contrib/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants