rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Bazel 5 java_runtime_version CLI parameters don't override system ones

Open YorikSar opened this issue 3 years ago • 1 comments

Describe the bug If I don't have Java installed or present in JAVA_HOME and PATH env variables, I can't build Java project even if I specify --tool_java_runtime_version=remotejdk_11 --java_runtime_version=remotejdk_11:

Error in fail: Auto-Configuration Error: Cannot find Java binary bin/java in /private/var/tmp/_bazel_tweag/decaa88e167f29f805e634aae0c83deb/external/local_jdk/nosystemjdk; either correct your JAVA_HOME, PATH or specify Java from remote repository (e.g. --java_runtime_version=remotejdk_11

To Reproduce On macOS without Java installed, enter examples/toolchains/java directory and run

nix-shell --run 'bazel run --tool_java_runtime_version=remotejdk_11 --java_runtime_version=remotejdk_11 :hello'

Expected behavior Example should be built using downloaded JDK

Environment

  • OS name + version: macOS Monterey 12.2.1
  • Version of the code:

Additional context See https://github.com/tweag/rules_nixpkgs/pull/185#issuecomment-1054227701 for the context where this has been found. I tried to add the problematic argument to global bazelrc on clean Ubuntu VM and didn't manage to reproduce this issue using upstream Bazel bindist.

YorikSar avatar Mar 04 '22 13:03 YorikSar

To copy the extra context from https://github.com/tweag/rules_nixpkgs/pull/185: It seems to be specifically a Nix provided Bazel with a rules_java provided toolchain that fails in this way. A Nix provided Bazel with a rules_nixpkgs provided Java toolchain and a Bazel bindist (e.g. via bazelisk) and a rules_java provided toolchain on the other hand seem to be working fine.

aherrmann avatar Mar 04 '22 14:03 aherrmann