Skip to content

Conversation

@evis
Copy link

@evis evis commented Dec 1, 2025

Resolves issue where imports from transitive proto_library dependencies were not resolved in IntelliJ.

The plugin now correctly adds scalapb JAR files from transitive proto_library dependencies to the module classpath, enabling proper import resolution for scala_proto_library targets with nested proto dependencies.

Fixes BAZEL-2695

Impact

With this PR, this transitive proto import is now resolved correctly and no longer shows as red in IntelliJ.

Scale of the problem:

  • In just one service (~220k lines of code), this PR fixes 679 red import cases
  • Across our entire repository (~4 million lines of code), the number of affected imports is much higher

This is a significant developer experience improvement for our team. In our Scala code, it's very common to use classes from transitive proto_library dependencies, and currently all such imports show as unresolved.

This has been a persistent pain point for developers working with Scala and protobuf, as it makes code navigation much more difficult when imports appear broken even though they compile correctly with Bazel.

Resolves issue where imports from transitive proto_library dependencies
were not resolved in IntelliJ.

The plugin now correctly adds scalapb JAR files from transitive
proto_library dependencies to the module classpath, enabling proper
import resolution for scala_proto_library targets with nested proto
dependencies.

Fixes [BAZEL-2695](https://youtrack.jetbrains.com/issue/BAZEL-2695)
val interfacesAndBinariesFromTargetsToImport =
measure("Collect interfaces and classes from targets to import") {
collectInterfacesAndClasses(targetsToImport)
collectInterfacesAndClasses(targetsToImport, allTargets)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to pass allTargets through several method calls like this?

val bazelBinPath =
bazelPathsResolver
.workspaceRoot()
.resolve("bazel-bin")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I rely on the bazel-bin symlink here? I noticed that other JAR files are resolved using direct paths.

Should I use a consistent approach? How would you recommend doing it?

* Excludes direct scala_proto_library dependencies to avoid duplicating JARs that are already
* included by the plugin's standard processing.
*/
private fun findTransitiveProtoLibraries(target: TargetInfo, allTargets: Map<Label, TargetInfo>): Set<TargetInfo> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does extracting the transitive proto_library dependency graph for each scala_proto_library target seem reasonable? Or would you prefer a different approach to fix the original problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant