Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions springboot/default_bazelrun_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ current_dir=$(pwd)
if [ -f "${BAZEL_RUN_JAVA}" ]; then
echo "Selected the JVM using the BAZEL_RUN_JAVA environment variable."
java_cmd=$BAZEL_RUN_JAVA
elif [ -f "$JAVA_RUNTIME" ]; then
echo "Selected the JVM using the Bazel Java Runtime: $JAVA_RUNTIME"
java_cmd=$JAVA_RUNTIME
elif [ -f "$JAVA_TOOLCHAIN" ]; then
echo "Selected the JVM using the Bazel Java toolchain: $JAVA_TOOLCHAIN_NAME"
java_cmd=$JAVA_TOOLCHAIN
Expand Down
15 changes: 15 additions & 0 deletions springboot/springboot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ else
JAVA_TOOLCHAIN_NAME=%java_toolchain_name_attr%
fi

JAVA_RUNTIME=${exec_root}%java_runtime_attr%

# the env variables file is found in SCRIPT_DIR
source $SCRIPT_DIR/%name%_bazelrun_env.sh

Expand All @@ -292,11 +294,15 @@ def _springboot_rule_impl(ctx):
ctx.attr.genjar_rule.files,
])

java_runtime = ctx.attr.bazelrun_runtime_jdk[java_common.JavaRuntimeInfo]
java_runtime_path = "%s/bin/java" % java_runtime.java_home

# resolve the full path of the launcher script that runs "java -jar <springboot.jar>" when calling
# "bazel run" with the springboot target (bazel run //examples/helloworld) and string sub it
# into the _bazelrun_script_template text defined above
outer_bazelrun_script_contents = _bazelrun_script_template \
.replace("%bazelrun_script%", ctx.attr.bazelrun_script.files.to_list()[0].short_path) \
.replace("%java_runtime_attr%", java_runtime_path) \
.replace("%name%", ctx.attr.name)

# the bazelrun_java_toolchain optional, if set, we use it as the jvm for bazel run
Expand Down Expand Up @@ -356,6 +362,14 @@ _springboot_rule = rule(
default = "@bazel_tools//tools/jdk:current_java_toolchain",
providers = [java_common.JavaToolchainInfo],
),
"bazelrun_runtime_jdk": attr.label(
default = Label("@rules_java//toolchains:current_java_runtime"),
#default = Label("@rules_java//toolchains:current_host_java_runtime"),
#default = Label("@bazel_tools//tools/jdk:current_host_java_runtime"),
#default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
cfg = "exec",
),
},
)

Expand All @@ -379,6 +393,7 @@ def springboot(
javaxdetect_ignorelist = None,
include_git_properties_file=True,
bazelrun_java_toolchain = None,
bazelrun_runtime_jdk = None,
bazelrun_script = None,
bazelrun_jvm_flags = None,
bazelrun_jvm_flag_list = None,
Expand Down