Unable to use BEF for a BUILD file in the root workspace directory
bmuschko opened this issue · 6 comments
I installed the version 1.5.0 of the plugin. When trying to import the workspace of a project, I get the error message shown in the attached screenshot. Is the issue that the BUILD
file lives on the same level as the WORKSPACE
file? I can see that other projects can be imported but they define Bazel packages in subdirectories.
You can find the example code here: https://github.com/bmuschko/getting-started-with-bazel/tree/master/exercises/02-java-binary/solution
OK I can look at it later today. Normally this is caused because the command line build failed. Bazel Eclipse uses Bazel itself to determine the dependency graph of a package, and if there are compile errors this can get derailed.
Can you verify that before you import the workspace, bazel build //... is successful (from the command line)?
Yes, bazel build //...
works fine. Side note: The workspace file is empty but that shouldn't cause an issue. Use case: a microservice does not define any dependencies and therefore doesn't need rules_jvm_external
.
I did verify that this is caused by having the BUILD file in the root of the workspace. We used to explicitly say that we don't support it, but that doc got refactored and we need to add that doc back. I will also re-assess how hard it would be to support. The main issue is we create a synthetic workspace project to provide IDE visibility to the WORKSPACE, and contains the global classpath search index. It would be ideal to create a second Eclipse project for root dir, for cases like these. Not sure how well Eclipse supports that. Under the covers Eclipse supports file linking so it might be possible to link the WORKSPACE to the synthetic workspace project, and the BUILD file to a Java project.
Also, it gives that specific error message because no results are coming back for buildable targets in a subdir of the root directory, which is the common error condition when the workspace is not buildable. We should make that more sophisticated to detect that the workspace is buildable but no targets were found that are usable.
I was able to implement this over the weekend. It wasn't too hard, in the end.
I still need to add some JUnit test cases, do more manual testing, and test on Windows.
A test workspace for this configuration is:
https://github.com/salesforce/bazel-demo/tree/main/other_usecases/java/java_rootbuildfile
This was released in BEF 1.5.2.