examples
examples copied to clipboard
:greeter target in java-tutorial is not there
Hi there is a dependency :greeter
here that doesn't even exist. Neither one of the java_binary
rules in the java-tutorial executes as a runner when running bazel run //<target>
.
Still failing in 2022. I think there' a missing BUILD file:
$ cd java-tutorial/
$ bazel build //src/main/java/com/example/cmdline:runner
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
ERROR: /path/to/bazel_examples/java-tutorial/src/main/java/com/example/cmdline/BUILD:3:12: no such target '//:greeter': target 'greeter' not declared in package '' defined by /path/to/bazel_examples/java-tutorial/BUILD and referenced by '//src/main/java/com/example/cmdline:runner'
ERROR: Analysis of target '//src/main/java/com/example/cmdline:runner' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.150s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
This project is mentioned in https://docs.bazel.build/versions/main/tutorial/java.html
Root level build file should be:
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "greeter",
srcs = glob(["src/main/java/com/example/*.java"]),
visibility = ["//visibility:public"],
)
I think the dependency should be on ProjectRunner
instead.
Since the docs talk a lot about ProjectRunner
.
At the same time I'm not sure why ProjectRunner
is a java_binary
and not a java_library
.
I added the pull request which will make the instructions in the tutorial work. Specifically https://bazel.build/start/java#use_multiple_packages .