lightbend / kalix-jvm-sdk

Java and Scala SDKs for Kalix
https://docs.kalix.io/java/index.html
Other
58 stars 39 forks source link

IntelliJ doesn't pick up proto annotations dependency #383

Open johanandren opened 3 years ago

johanandren commented 3 years ago

Importing and build a fresh project from the maven archetype in IntelliJ (v 212.4746.92 with bundled protobuf plugin version) still marks the protobuf dependencies as unknown/red. Is there something we are missing doing or is it a shortcoming of the protobuf plugin (seems like plugin docs says you need to add non source protobuf paths manually https://github.com/jvolkman/intellij-protobuf-editor#path-settings)?

Screenshot 2021-09-14 at 10 37 14 Screenshot 2021-09-14 at 10 41 22
johanandren commented 3 years ago

Related upstream issue in protobuf editor plugin: https://github.com/jvolkman/intellij-protobuf-editor/issues/30

johanandren commented 2 years ago

Issue now in the IntelliJ tracker rather than that repo: https://youtrack.jetbrains.com/issue/IDEA-280610

ennru commented 2 years ago

Even the generated sources directories are not always picked up correctly.

johanandren commented 2 years ago

Splitted out the source directories to a separate task as it is not quite the same.

Not entirely sure we can do anything here, would need a fix/change in the IntelliJ protobuf plugin.

ennru commented 2 years ago

Some hint came in on this:

The only way I could see to get Intellij to recognize the proto files is by using the Path Settings. This works well for proto files included in the project, but it didn't seem to work when proto files were provided in a jar as a dependency. Such as with the Kalix protocol.

You'll notice by default when you open the path settings, there'll be some references/entries to the projects src, and the last entry is for the default provided google proto files located in the following location, at least for mac..

/Users/username/Library/Caches/JetBrains/IntelliJIdea2022.1/protoeditor As "hacky" as it is, what I found to work is unzipping the Kalix protocol jar, and grabbing the Kalix and Google API proto files, and copying them to this "protoeditor" directory. Once I did that, the editor was able to recognize them.

This basically resolved the editor not being able to pick up the dependencies, however even without that, the project would still build and compile without issue. So this little hack just helps the editor find the right dependencies.

I tried different variations of trying to directly reference the jar in the path settings for the protobuf plugin, but nothing else seemed to work. So manually copying the proto files to the protoeditor directory seemed to work.

johanandren commented 2 years ago

Trying out the hint in this comment: https://github.com/jvolkman/intellij-protobuf-editor/issues/64#issuecomment-817961346 adding a random directory, then editing the path in the IntelliJ protobuf path list to be jar:///Users/johan/.m2/repository/io/kalix/kalix-sdk-protocol/1.0.0-M2/kalix-sdk-protocol-1.0.0-M2.jar!/ works (but it's quite a nuisance so not really a reasonable workaround imo)

johanandren commented 2 years ago

Tried out the third party Protobuf plugin from https://github.com/devkanro/intellij-protobuf-plugin/releases/tag/v1.5.20

It seems to work very nicely, picking up the right messages and annotations from jar dependencies both in a sample maven project and a sample scala/sbt project.

Installing it requires disabling the default plugins for Protobuf and gRPC shipped with IntelliJ first, so that is a bit cumbersome.

johanandren commented 2 years ago

Since I forgot this already once: Note that this does work as expected for the Scala SDK already, only the Java SDK with maven has the problem.