bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
761 stars 303 forks source link

Auto-Configuration Error: Cannot find Java binary #6141

Open Isachenko1a1v opened 7 months ago

Isachenko1a1v commented 7 months ago

Description of the issue. Please be specific.

After cloning simplest project https://github.com/bazelbuild/examples/tree/main/java-tutorial i tried to import it as Bazel Project and got an error:

ERROR: /home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0~toolchains~local_jdk/BUILD.bazel:2:10: in fail_rule rule @@rules_java~7.1.0~toolchains~local_jdk//:jdk: 
Traceback (most recent call last):
    File "/home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0/toolchains/fail_rule.bzl", line 19, column 13, in _fail_rule_impl
        fail("%s %s" % (ctx.attr.header, ctx.attr.message))
Error in fail: Auto-Configuration Error: Cannot find Java binary bin/java in /home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0~toolchains~local_jdk/nosystemjdk; either correct your JAVA_HOME, PATH or specify Java from remote repository (e.g. --java_runtime_version=remotejdk_11)

I can't Sync project. However i can build it via CLI: bazel build //:ProjectRunner ... INFO: Build completed successfully, 8 total actions

JAVA_HOME is set: echo $JAVA_HOME /home/andrei/.sdkman/candidates/java/current

What's the simplest set of steps to reproduce this issue? Please provide an example project, if possible.

git clone https://github.com/bazelbuild/examples rm -fr examples/java-tutorial/src/main/java/com/example/cmdline (this folder will cause errors)

Open Intellij => Import Bazel Project => examples/java-tutorial =>create from scratch =>next =>create => Error in console

Command: /usr/local/bin/bazel build --tool_tag=ijwb:IDEA:community --keep_going --build_event_binary_file=/tmp/intellij-bep-a9d671c8-a14d-4828-97ed-0dcc703e51be --nobuild_event_binary_file_path_conversion --curses=no --color=yes --progress_in_terminal_title=no --noexperimental_run_validations --aspects=@@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect --override_repository=intellij_aspect=/home/andrei/.local/share/JetBrains/IdeaIC2023.3/ijwb/aspect --output_groups=intellij-resolve-java-direct-deps,intellij-info-generic,intellij-info-java-direct-deps -- //:ProjectRunner
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Analyzing: target //:ProjectRunner (0 packages loaded, 0 targets configured)
Analyzing: target //:ProjectRunner (0 packages loaded, 0 targets configured)
[0 / 1] checking cached actions
ERROR: /home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0~toolchains~local_jdk/BUILD.bazel:2:10: in fail_rule rule @@rules_java~7.1.0~toolchains~local_jdk//:jdk: 
Traceback (most recent call last):
    File "/home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0/toolchains/fail_rule.bzl", line 19, column 13, in _fail_rule_impl
        fail("%s %s" % (ctx.attr.header, ctx.attr.message))
Error in fail: Auto-Configuration Error: Cannot find Java binary bin/java in /home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0~toolchains~local_jdk/nosystemjdk; either correct your JAVA_HOME, PATH or specify Java from remote repository (e.g. --java_runtime_version=remotejdk_11)
ERROR: /home/andrei/.cache/bazel/_bazel_andrei/0548cb6cba6f840ddd669cbbf440adf3/external/rules_java~7.1.0~toolchains~local_jdk/BUILD.bazel:2:10: Analysis of target '@@rules_java~7.1.0~toolchains~local_jdk//:jdk' failed
WARNING: errors encountered while analyzing target '//:ProjectRunner', it will not be built.
Analysis failed
INFO: Analyzed target //:ProjectRunner (75 packages loaded, 1118 targets configured).
WARNING: errors encountered while analyzing target '//:ProjectRunner', it will not be built.
Analysis failed
INFO: Found 0 targets...
ERROR: command succeeded, but not all targets were analyzed
INFO: Elapsed time: 0.892s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
FAILED: 
INFO: Build Event Protocol files produced successfully.

if i run command from the logs in separate terminal - it works:

/usr/local/bin/bazel build --tool_tag=ijwb:IDEA:community --keep_going --build_event_binary_file=/tmp/intellij-bep-a9d671c8-a14d-4828-97ed-0dcc703e51be --nobuild_event_binary_file_path_conversion --curses=no --color=yes --progress_in_terminal_title=no --noexperimental_run_validations --aspects=@@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect --override_repository=intellij_aspect=/home/andrei/.local/share/JetBrains/IdeaIC2023.3/ijwb/aspect --output_groups=intellij-resolve-java-direct-deps,intellij-info-generic,intellij-info-java-direct-deps -- //:ProjectRunner
WARNING: Running Bazel server needs to be killed, because the startup options are different.
Starting local Bazel server and connecting to it...
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Analyzing: target //:ProjectRunner (1 packages loaded, 0 targets configured)
Analyzing: target //:ProjectRunner (1 packages loaded, 0 targets configured)
[0 / 1] checking cached actions
INFO: Analyzed target //:ProjectRunner (77 packages loaded, 1317 targets configured).
INFO: Found 1 target...
Aspect @@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect of //:ProjectRunner up-to-date:
  bazel-bin/external/rules_java~7.1.0/toolchains/current_java_toolchain--1286701614.intellij-info.txt
  bazel-bin/ProjectRunner.java-manifest
  bazel-bin/ProjectRunner--510079095.intellij-info.txt
  bazel-bin/ProjectRunner.jar
  bazel-bin/ProjectRunner-src.jar
  bazel-bin/ProjectRunner.jdeps
[15 / 15] checking cached actions
INFO: Elapsed time: 3.689s, Critical Path: 0.11s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: 
INFO: Build Event Protocol files produced successfully.

Version information

IdeaCommunity: Build #IC-233.14475.28, built on February 13, 2024

Runtime version: 17.0.10+1-b1087.17 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Platform: Ubuntu 6.5.0-18-generic

Bazel for IntelliJ plugin: 2024.01.30.0.1-api-version-233 Bazel: 7.0.2

Isachenko1a1v commented 7 months ago

Update: Tried to run intellij via CLI /snap/intellij-idea-community/483/bin/idea.sh And everything started working correctly.