bazel-eclipse icon indicating copy to clipboard operation
bazel-eclipse copied to clipboard

BEF: package cannot be imported if source directories are nested within each other

Open plaird opened this issue 2 years ago • 2 comments

We had an internal case where the package was structured like this:

  • //a/b/c/foo/src/main/java/com/foo/A.java
  • //a/b/c/foo/src/main/resources/xyz.properties
  • //a/b/c/foo/src/test/resources/test.properties
  • //a/b/c/foo/bar.config
  • //a/b/c/foo/BUILD

The bar.config file is a configuration file passed into a custom rule and loaded with a $location var. This failed to import, with error:

Java Model Exception: Java Model Status [Cannot nest 'foo/src/main/java' inside 'foo/src'. To enable nesting exclude 'main/' from 'foo/src']

plaird avatar Mar 16 '22 06:03 plaird

Cause: The first issue is the MavenProjectStructureStrategy failed to apply itself because the package is missing a src/test/java directory. This is fine, as it ultimately is a performance optimization. The BazelQueryProjectStructureStrategy was then invoked to determine the project structure the expensive way. The Bazel query issued is this:

bazel query "kind('source file', deps(//a/b/c/foo:*))"

which returns entries including:

  • //a/b/c/foo:src/main/java/com/foo/A.java
  • //a/b/c/foo:bar.config

The strategy then makes foo/src/main/java a source folder, but also wants to add foo as a source folder since there is a Bazel-consumed resource file there. Eclipse does not allow this nesting of source folders.

plaird avatar Mar 16 '22 06:03 plaird

After review, I do not think this is supportable in Eclipse. Eclipse requires source folders to be distinct locations on the file system and cannot overlap each other within a project. This Issue will remain unresolved.

plaird avatar Apr 19 '22 06:04 plaird