Java package annotation
This rule enforces that every proto file for a public API surface sets
option java_package
, as mandated in AIP-191.
Details
This rule looks at each proto file, and complains if the java_package
file
annotation is not present, or set to empty string.
Examples
Incorrect code for this rule:
// Incorrect.
syntax = "proto3";
package google.example.v1;
// Needs `option java_package = "com.google.example.v1";`.
option java_multiple_files = true;
option java_outer_classname = "LibraryProto";
// Incorrect.
syntax = "proto3";
package google.example.v1;
option java_package = "google.example"; // Should end with "google.example.v1".
option java_multiple_files = true;
option java_outer_classname = "LibraryProto";
Correct code for this rule:
// Correct.
syntax = "proto3";
package google.example.v1;
option java_package = "com.google.example.v1";
option java_multiple_files = true;
option java_outer_classname = "LibraryProto";
Disabling
If you need to violate this rule, use a comment at the top of the file. Remember to also include an aip.dev/not-precedent comment explaining why.
// (-- api-linter: core::0191::java-package=disabled
// aip.dev/not-precedent: We need to do this because reasons. --)
syntax = "proto3";
package google.example.v1;
option java_multiple_files = true;
option java_outer_classname = "LibraryProto";