Java package annotation

This rule enforces that every proto file for a public API surface sets option java_outer_classname, as mandated in AIP-191.

Details

This rule looks at each proto file, and complains if the java_outer_classname file annotation is not present, or set to empty string. It recommends a sensible default based on the filename, but does not complain if the value is set to something else.

Examples

Incorrect code for this rule:

// Incorrect.
syntax = "proto3";

package google.example.v1;

option java_package = "com.google.example.v1";
option java_multiple_files = true;
// Needs `option java_outer_classname = "LibraryProto";` or similar.

message Book {}

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";

message Book {}

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-outer-classname=disabled
//     aip.dev/not-precedent: We need to do this because reasons. --)
syntax = "proto3";

package google.example.v1;

option java_package = "com.google.example.v1";
option java_multiple_files = true;

message Book {}