examples icon indicating copy to clipboard operation
examples copied to clipboard

:greeter target in java-tutorial is not there

Open sfc-gh-martz opened this issue 3 years ago • 1 comments

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>.

sfc-gh-martz avatar Oct 08 '21 00:10 sfc-gh-martz

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"],
)

paul-hammant avatar Apr 10 '22 15:04 paul-hammant

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.

ittaiz avatar Oct 30 '22 10:10 ittaiz

I added the pull request which will make the instructions in the tutorial work. Specifically https://bazel.build/start/java#use_multiple_packages .

antoinell avatar Jun 25 '23 20:06 antoinell