bazelbuild / intellij

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

IntelliJ Fast Run / Debug does not automatically pick the correct path to `java` in the runfiles directory #6554

Open JohnnyMorganz opened 2 weeks ago

JohnnyMorganz commented 2 weeks ago

Description of the bug:

I am trying to use the Fast Run feature of the intellij plugin for bazel. In our setup, we are using the default Java toolchains with a remote JDK toolchain, which is used for hermetic testing and compilation: https://bazel.build/docs/bazel-and-java#hermetic-testing

When trying to run a fast build, I get the following error

Error running 'Bazel test <class name>'
Cannot run program "../local_jdk/bin/java" (in directory "<runfiles directory>"): error=2, No such file or directory

In our setup, the java binary is present at ../remotejdk11_linux/bin/java.

Looking at the code, it seems the fast build set up is hardcoded to look for the local_jdk, rather than the jdk configured in our toolchain

https://github.com/bazelbuild/intellij/blob/eaa6b201614982ab0eeb022843faea6e6151218c/java/src/com/google/idea/blaze/java/run/fastbuild/BazelFastBuildTestEnvironmentCreator.java#L29

I would expect the plugin to identify what is the toolchain setup, and pick the appropriate path to the java binary.

Which category does this issue belong to?

Intellij

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create a fresh bazel WORKSPACE with a simple java test target and add the following to your .bazelrc:

build--tool_java_runtime_version=remotejdk_11 --tool_java_language_version=11
build--java_runtime_version=remotejdk_11 --java_language_version=11

Open the project in IntelliJ and start a Bazel sync. Try to Fast Run your test class. It should fail with the above error message

Which Intellij IDE are you using? Please provide the specific version.

IntelliJ IDEA 2024.1 Build #JBC-241.14494.240

What programming languages and tools are you using? Please provide specific versions.

Java 11, Bazel 7.2.1

What Bazel plugin version are you using?

2024.06.18.0.1-api-version-241

Have you found anything relevant by searching the web?

I found #6431 which introduces an option to manually specific the path to the java binary in the runfiles directory. As a work around, I can set this to remotejdk11_linux/bin/java manually.

However, this is quite fragile, as now if we ever make changes to our toolchain setup then end users' fast runs will break

Any other information, logs, or outputs that you want to share?

No response