bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://github.com/bazelbuild/intellij/blob/master/docs/index.md
Apache License 2.0
764 stars 308 forks source link

Autoattaching generated srcjars doesn't work for kt_jvm_library , kt_jvm_binary, java_lib #6547

Open prodoelmit opened 5 months ago

prodoelmit commented 5 months ago

Description of the bug:

There is functionality that finds srcjars generated as part of bazel build and attaches them to project as dependency.

For me this feature does only work when srcjar contains .java files and is passed to java_binary rule as source Cases where srcjars are not picked up (but should):

Example where it works: image

Example where it doesn't: image

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.

Repo with reproduction: https://github.com/prodoelmit/bazel_example_generated_srcjar

Which Intellij IDE are you using? Please provide the specific version.

2023.3.5 Ultimate (#IU-233.14808.21)

What programming languages and tools are you using? Please provide specific versions.

Kotlin

What Bazel plugin version are you using?

7.0.0

Have you found anything relevant by searching the web?

There are numerous issues about adding support for srcjars: #6261, #5250, #6286, #5776

I've tried getting help in slack: https://bazelbuild.slack.com/archives/CHSV3RSR0/p1719696952077309 , also there are several threads about it: https://bazelbuild.slack.com/archives/CHSV3RSR0/p1592928891054900 , https://bazelbuild.slack.com/archives/CHSV3RSR0/p1571351050011200

Any other information, logs, or outputs that you want to share?

Everything's in reproduction repo

tpasternak commented 1 week ago

There are numerous issues about adding support for srcjars: https://github.com/bazelbuild/intellij/pull/6261, https://github.com/bazelbuild/intellij/pull/5250, https://github.com/bazelbuild/intellij/pull/6286, https://github.com/bazelbuild/intellij/pull/5776

Well, I'll try to look into that tomorrow or next week. Please note that the PRs above target Query Sync https://github.com/bazelbuild/intellij/blob/master/docs/querysync.md

tpasternak commented 1 week ago

Reproduced. java_binary case triggers jar filtering and that's why it works

tpasternak commented 1 week ago

Well, this was one of the most surprising findings in this plugin. It seems that there is a threshold at which the plugins assumes a jar file is empty and therfore removes it from the project structure :O

https://github.com/bazelbuild/intellij/blob/3f81565b4aede217e160adc97a3f3b619bfa0498/java/src/com/google/idea/blaze/java/sync/importer/emptylibrary/EmptyLibraryFilter.java#L42-L50

tpasternak commented 1 week ago

To sum up - there are two different issues here. Fixes are on their way. In the meantime:

Workarounds:

  1. bazel_binary problem:

    • Open Help -> custom vm options
    • add -Dblaze.experiment.blaze.empty.jar.threshold=0
    • and -Dblaze.experiment.blaze.nonempty.jar.threshold=1
  2. kt_jvm_library issue

    • please just don't mix both kt and srcjar sources in a single rule. Create separate kt_jvm_libraries for these