I wrote a small application and used java_binary as follows:
java_binary(
name = "MyCommand",
srcs = [
"MyCommand.java",
],
visibility = ["//visibility:public"],
deps = [
"//src/main/java/com/example/two",
],
)
It depends on a java_library target //src/main/java/com/example/two
I then wrote a java_test as follows:
java_test(
name = "TestMyCommand",
size = "small",
srcs = [
"TestMyCommand.java",
],
deps = [
":MyCommand",
],
)
The test is pretty simple and just does new MyCommand().
This unfortunately fails quickly with a ClassDefNotFoundException with a class file found in //src/main/java/com/example/two. Setting a breakpoint it looks like that library is not included in the ClassPath.
HOWEVER, if I change my java_test to depend on a java_library THEN the transitive dependency of //src/main/java/com/example/two is included.
I could not find anything in the documentation explaining why?