Skip to content

Commit

Permalink
set version field of java_runtime
Browse files Browse the repository at this point in the history
Using JDK 17+, java_test rules fail if Bazel cannot determine the runtime version from the JavaRuntimeInfo provider, since the java security manager was deprecated in that version.

See also: bazelbuild/bazel@7556e11
  • Loading branch information
malt3 committed Jun 10, 2024
1 parent 6c96398 commit ed4c45b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions toolchains/java/java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ with import <nixpkgs> { config = {}; overlays = []; };
{ attrPath
, attrSet
, filePath
, javaToolchainVersion
}:
let
Expand All @@ -41,6 +42,10 @@ let
else
"${javaHome}/${filePath}"
;
versionArg = if javaToolchainVersion == null then
"# version not set"
else
"version = ${javaToolchainVersion},";
in
pkgs.runCommand "bazel-nixpkgs-java-runtime"
Expand All @@ -58,6 +63,7 @@ pkgs.runCommand "bazel-nixpkgs-java-runtime"
java_runtime(
name = "runtime",
java_home = r"${javaHomePath}",
${versionArg}
visibility = ["//visibility:public"],
)
EOF
Expand Down Expand Up @@ -238,6 +244,12 @@ def nixpkgs_java_configure(
"filePath",
java_home_path,
])
if toolchain_version:
nixopts.extend([
"--argstr",
"javaToolchainVersion",
toolchain_version,
])

nixpkgs_package(
name = name,
Expand Down
1 change: 1 addition & 0 deletions toolchains/java/local_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def local_java_runtime(name, java_home, version, runtime_name = None, visibility
native.java_runtime(
name = runtime_name,
java_home = java_home,
version = version,
visibility = visibility,
)

Expand Down

0 comments on commit ed4c45b

Please sign in to comment.