github.com/googleapis/api-linter@v1.65.2/docs/rules/0191/java-package.md (about)

     1  ---
     2  rule:
     3    aip: 191
     4    name: [core, '0191', java-package]
     5    summary: All proto files must set `option java_package`.
     6  permalink: /191/java-package
     7  redirect_from:
     8    - /0191/java-package
     9  ---
    10  
    11  # Java package annotation
    12  
    13  This rule enforces that every proto file for a public API surface sets
    14  `option java_package`, as mandated in [AIP-191][].
    15  
    16  ## Details
    17  
    18  This rule looks at each proto file, and complains if the `java_package` file
    19  annotation is not present, or set to empty string.
    20  
    21  ## Examples
    22  
    23  **Incorrect** code for this rule:
    24  
    25  ```proto
    26  // Incorrect.
    27  syntax = "proto3";
    28  
    29  package google.example.v1;
    30  
    31  // Needs `option java_package = "com.google.example.v1";`.
    32  option java_multiple_files = true;
    33  option java_outer_classname = "LibraryProto";
    34  ```
    35  
    36  ```proto
    37  // Incorrect.
    38  syntax = "proto3";
    39  
    40  package google.example.v1;
    41  
    42  option java_package = "google.example";  // Should end with "google.example.v1".
    43  option java_multiple_files = true;
    44  option java_outer_classname = "LibraryProto";
    45  ```
    46  
    47  **Correct** code for this rule:
    48  
    49  ```proto
    50  // Correct.
    51  syntax = "proto3";
    52  
    53  package google.example.v1;
    54  
    55  option java_package = "com.google.example.v1";
    56  option java_multiple_files = true;
    57  option java_outer_classname = "LibraryProto";
    58  ```
    59  
    60  ## Disabling
    61  
    62  If you need to violate this rule, use a comment at the top of the file.
    63  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    64  
    65  ```proto
    66  // (-- api-linter: core::0191::java-package=disabled
    67  //     aip.dev/not-precedent: We need to do this because reasons. --)
    68  syntax = "proto3";
    69  
    70  package google.example.v1;
    71  
    72  option java_multiple_files = true;
    73  option java_outer_classname = "LibraryProto";
    74  ```
    75  
    76  [aip-191]: https://aip.dev/191
    77  [aip.dev/not-precedent]: https://aip.dev/not-precedent