Mapping from Maven standard directory to Bazel for test resources

前端 未结 1 1751
花落未央
花落未央 2021-01-19 05:52

We have test dependency files in src/test/resources per the Maven Standard Directory Layout. These test files end up in the JAR and on the classpath when test c

相关标签:
1条回答
  • 2021-01-19 06:32

    Yes, that is the recommended approach. As mentioned in the docs for resources, Bazel understands the Maven Standard Directory Layout and will put the data files at the right classpath:

    The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's standard directory layout, (a "src" directory followed by a "resources" directory grandchild).

    If you wanted to bundle the resource separately, you could create a resources-only jar and then depend on it with the resource_jars attribute.

    Edit: as Ittai points out below, Bazel will not introspect resources, so you'd have to be careful not to end up with any collisions (e.g., pkg1/src/main/resources/foo and pkg2/src/main/resources/foo). Neither resources not resource_jars will check this for you, so if this is a concern, you might want to put any resources you need in a filegroup and have a genrule target or test that checks for collisions.

    0 讨论(0)
提交回复
热议问题