I am using the protobuf gradle plugin (https://github.com/google/protobuf-gradle-plugin) to generate .java files from protbufs made by a different team at my company.
My setup looks like so
protobuf {
generatedFilesBaseDir = "$projectDir/src/main/java"
protoc {
artifact = "com.google.protobuf:protoc:${LibraryVersion.PROTOC}"
}
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${LibraryVersion.GRPC_PROTOBUF}"
}
}
}
The files generate successfully under the directory structure like so:
root
protobuf
protobuf-files
build.gradle.kts
src
main
java
main
java
com
companyname
protobuf
The files are generated with the package name of
package com.companyname.protobuf.reader;. Basically everything in /src is auto generated using the config I listed above.
The problem is that when I use these files in code like so
import com.companyname.protobuf.reader.SomeClass1
import com.companyname.protobuf.reader.SomeClass
import com.companyname.protobuf.reader.SomeOtherClass
import com.companyname.protobuf.reader.ClassClassClass
typealias TestID = com.companyname.protobuf.someclass.UUID128
abstract class CentralManager {
I can build the project fine, and it even works correctly. The issue is that because the package name is different, my IDE fails to resolve it, and it highlights all of the protobuf items in red, even though I can build and run everything just fine.
I see Unresolved reference: protobuf
Unfortunately, the protobufs themselves specify a package like package me.company.protobuf.reader; and I am not able to change this, as it comes from a different team that controls this.
The error I see in the actual generated protobuf file is
Package name 'com.companyname.protobuf.reader' does not correspond to the file path 'main.java.com.companyname.protobuf.reader'
I understand what the error means, but I am not quite sure how to fix it. Any tips are appreciated. I cannot just simply move the files, as they are auto generated. I need to have them generate at a correct path, or create a way for the IDE to correctly match the files to their actual package location.