Search code examples
protocol-buffers

Setting a correct package name for a .proto file


After reading the documentation for Google's Protocol Buffers I wished to implement them in my client, so far I have the following:

package com.christopher.kade;
option java_package= "protocol";

message Protocol {
    required string keyword = 1;
    optional string value = 2;
    optional string type = 3;
}

But when generated, the file has as a package "protocol" and therefore IntellIJ gives me the following error:

Package name 'protocol' does not correspond to the file path 'com.christopher.kade.protocol'

Please note that if I take away the option, the plugin creates a new package called com.christopher.kade.

What should I add to my .proto file in order to have the right package name?


Solution

  • I think you should use the same full package name in package and java_package to make it work:

    package com.christopher.kade.protocol;
    option java_package= "com.christopher.kade.protocol";