Reputation: 21
I am trying to use Bazel for java tests. And need to access data files under resources. My project has standard Maven structure. I am using filegroup for the resources and have it as dependency in java_test.
The issue is when i try to run the test, it fails with following error java.lang.RuntimeException: org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file:/private/var/tmp/_bazel_username/2c26269e9af968f4ce3e88b22720114e/execroot/myproject/bazel-out/darwin-fastbuild/bin/hadoop/com_company_hadoop_search_join_TermTest.jar!/com/company/hadoop/search/join/names.txt
I have following in my src/test/resources/BUILD:
filegroup(
name = "resources",
testonly = 1,
srcs = glob(["**/*.txt"]),
visibility = ["//visibility:public"],
)
And the following in my hadoop/BUILD:
java_test(
srcs =
["src/test/java/com/company/hadoop/search/join/TermTest.java"],
resources = ["//hadoop/src/test/resources:resources"],
deps = [
"//src/main/java/com/path/to/my/code",
"//:junit_junit",
],
)
I verified the test jar contents and text file does exist as expected.
Upvotes: 2
Views: 3169
Reputation: 26984
I believed your test "resources" are not java resources but data files.
Use the data attribute:
java_test(
srcs = [
"src/test/java/com/company/TermTest.java",
],
data = [
"//hadoop/src/test/resources:resources",
],
deps = [
"//src/main/java/com/path/to/my/code"
],
)
Upvotes: 2