-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntelliJ does not attach sources for generated Java files or srcjars unless an in-source file is also present #6658
Comments
@JohnnyMorganz can you please take a look into project structure and check what's there?
|
Hey @tpasternak With the If I then uncomment the line and resync, I see the following: I don't see any changes after navigating to the class files |
Could you please check this out? bazelbuild/bazel#22254 |
What I can recommend, is just to restructure the directories in a way they would match the heuristic described in the bazel ticket |
Thanks, although I'm not sure if that issue is exactly the same I created this minimal repro from a larger example. In that example, we are generating a
In my minimal example, I also have |
For completeness, with the following sources jar, the generated source file resolves correctly in IntelliJ:
If we remove test/Dummy.java and then rebuild, it does not resolve correctly. In the Intellij libraries panel, it lists the If I remove test/Dummy.java, this filtered gen src jar is not generated, and there is nothing added to libraries. |
Also just to simplify things a bit further, I changed the minimal example slightly so that the source paths match exactly with the Java package path. You can still repro the issue in this case. # test/BUILD.bazel
genrule(
name = "generated-test-class",
outs = ["TestClass.java"],
cmd = "\n".join([
'echo "',
"package test;",
"import org.junit.*;",
"public class TestClass {",
" @Test",
" public void exampleTest() {",
" throw new RuntimeException();",
" }",
"}",
'" > $@',
]),
)
java_test(
name = "test",
srcs = [
# "Dummy.java",
":generated-test-class",
],
test_class = "test.TestClass",
)
|
So I just tried to change java_test to java_library and reference it from yet another library. All the indexing was done correctly I could reference the symbols. |
Screen.Recording.2024-08-27.at.16.15.52.mov |
Interesting thanks, I indeed see the same behaviour that you see when I switch to java_library, however that isn't exactly the same structure that I had in the original issue. Do you experience the behaviour I mentioned originally when using a single java_test? (EDIT: or alternatively 2 targets with no in-source files in the second target, see video 4) I've attached some screen recordings showing my setup and what I see. Please let me know if there is anything else I should test: I cleaned my bazel output and restarted IntelliJ to ensure I was in a clean state. I'm using the blue links in terminal to indicate the correct source file was resolved or not, as well as checking the Libraries panel. Before with no Dummy file synced: NoDummyFile.movAfter we sync with the Dummy file: WithDummyFile.movTo double check, using a separate java library with a source file, like you mention: Screen.Recording.2024-08-27.at.17.35.29.movAlso, I removed the Dummy.java from the second build target and we get back to the same issue as before (however I did have to switch from Screen.Recording.2024-08-27.at.17.41.58.movFor context, the example I am minimising this from is a java test with only generated sources, no in-source files (i.e., video 1 and 4 above) |
Ok, thanks, now I understand the problem. However still, I don't have capacity to work on it |
That's fair enough, I think we can make do with the workaround by including a Dummy in-source file as part of the generated target. Thanks for taking the time to investigate! |
Description of the bug:
When trying to debug a failing Bazel Java test, one may want to step into the relevant Java file to explore and attach breakpoints. For
java_test
targets where the sources are solely composed of generated files, this is not possible.For example, in such a test, the test file is not link-able in the exception:
Selecting the test class in the side panel also does not direct us to the source file
However, if we also have Java source files (that may be completely irrelevant) as part of the
java_test
target, then Intellij shows a link and allows us to click through:Clicking the test on the side panel also works.
This happens both when the generated files are directly added to the
srcs
, or if they are packaged into a.srcjar
then the srcjar is added to thesrcs
.Which category does this issue belong to?
Intellij
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Create a build file as below:
Run bazel sync, then try running the target. You will see no link available.
Next, create a Dummy.java file and uncomment the "Dummy.java" line, then re-run Bazel sync
Try running the target, you will see links now appear and TestClass is accessible.
Writing the generated file into a .srcjar also reproduces the same issue
Which Intellij IDE are you using? Please provide the specific version.
IntelliJ IDEA 2024.1 Build #JBC-241.14494.240
What programming languages and tools are you using? Please provide specific versions.
Java 11, Bazel 7.2.1
What Bazel plugin version are you using?
2024.06.18.0.1-api-version-241
Have you found anything relevant by searching the web?
I've looked in the past issues, these look relevant but are not entirely the same problem. Linking in case it helps
-filtered-gen.jar
and-filtered-gen-src.jar
generated for packages without any.java
files #6407Any other information, logs, or outputs that you want to share?
If it helps, here is the
intellij-info
before and after the Dummy.java file is added. (A filtered gen jar is also created only when the sources are present, probably because of this -intellij/aspect/intellij_info_impl.bzl
Lines 687 to 695 in d55c435
Before
After
The text was updated successfully, but these errors were encountered: