I am migrating some integration tests from gradle to bazel for an application. As part of the integration test a resource is loaded like
final String resourcePath = SomeClass.class.getResource("/test.properties").getPath()
If I trace this code path, when I run this test from IntelliJ, for gradle, this path is an absolute path like
/Users/me/..../test.properties
However, in the case of bazel, it looks something like
file:/private/var/tmp/_bazel_me/4f1994ece960b360388a372b5e6aa4b2/execroot/project/bazel-out/darwin-fastbuild/bin/project/src/integrationTest/package/Test.jar!/test.properties
So this string resourcePath is provided to a framework that loads with
Files.exists(resourcePath)
This works for the absolute path but not for the jar based path. How do I get around this since I don't have any control over the framework code?
CodePudding user response:
If you're using the resources attribute of java_test or java_library, then indeed the resources are packaged inside the jar for that target:
https://docs.bazel.build/versions/main/be/java.html#java_test.resources
It sounds like you might want to try the data attribute instead, which puts files in the runfiles directory (i.e., the directory where the test / binary is executed). See the answer here: how to find path to Java source code files from JUnit tests execution via Bazel
