compiler: Default to @generated=omit (#12080)

After many years of issue 9179 being open, there's been nothing to show
that we need the javax.annotations.Generated annotation. Most tools use
file paths and a few check for annotations with "Generated" in the name.
ErrorProne has a few that check for javax.annotations.Generated, but
only UnnecessarilyFullyQualified looks like it'd be a problem and it is
disabled by default. We're not getting any more information, no users
have reported issues with `@generated=omit`, and the existing dependency
is annoying users, so just drop it.

Given we will still retain the GrpcGenerated annotation, it seems highly
likely things are already okay. Even if there are problems they would
probably be addressed by adding a io.grpc.stub.annotations.Generated
annotation or small tweaks. In the short-term, (non-Bazel) users can use
`@generated=javax`, but long-term we could consider removing the option
assuming we've resolved any outstanding issues.

We will want to update the examples and the README to remove the
org.apache.tomcat:annotations-api dependency after the next release.

Fixes #9179
This commit is contained in:
Eric Anderson 2025-05-21 10:19:30 -07:00 committed by GitHub
parent 2fb09578a8
commit f8700a13ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
49 changed files with 6 additions and 145 deletions

View File

@ -33,7 +33,6 @@ java_library(
"//api",
"//protobuf",
"//stub",
"//stub:javax_annotation",
"@com_google_protobuf//:protobuf_java",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
@ -47,7 +46,6 @@ java_library(
"//api",
"//protobuf-lite",
"//stub",
"//stub:javax_annotation",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
@ -67,6 +65,5 @@ java_library(
visibility = ["//:__subpackages__"],
exports = [
artifact("com.google.auto.value:auto-value-annotations"),
artifact("org.apache.tomcat:annotations-api"), # @Generated for Java 9+
],
)

View File

@ -41,7 +41,6 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
"io.perfmark:perfmark-api:0.27.0",
"junit:junit:4.13.2",
"org.apache.tomcat:annotations-api:6.0.53",
"org.checkerframework:checker-qual:3.12.0",
"org.codehaus.mojo:animal-sniffer-annotations:1.24",
]

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/gcp/handshaker.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class HandshakerServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to obtain stats for verifying LB behavior.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class LoadBalancerStatsServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/metrics.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class MetricsServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to control reconnect server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ReconnectServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* performance with various types of payload.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class TestServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* that case.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class UnimplementedServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to dynamically update the configuration of an xDS test client.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateClientConfigureServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to remotely control health status of an xDS test server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateHealthServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to obtain stats for verifying LB behavior.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class LoadBalancerStatsServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/metrics.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class MetricsServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to control reconnect server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ReconnectServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* performance with various types of payload.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class TestServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* that case.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class UnimplementedServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to dynamically update the configuration of an xDS test client.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateClientConfigureServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to remotely control health status of an xDS test server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateHealthServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/services.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class BenchmarkServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/services.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ReportQpsScenarioServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/services.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class WorkerServiceGrpc {

View File

@ -22,7 +22,6 @@ java_library(
"//api",
"//protobuf",
"//stub",
"//stub:javax_annotation",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
"@com_google_protobuf//:protobuf_java",
@ -35,7 +34,6 @@ java_library(
"//api",
"//protobuf-lite",
"//stub",
"//stub:javax_annotation",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],

View File

@ -184,7 +184,11 @@ protobuf {
inputs.file javaPluginPath
}
ofSourceSet('test').configureEach {
plugins { grpc {} }
plugins {
grpc {
option '@generated=javax'
}
}
}
ofSourceSet('testLite').configureEach {
builtins {
@ -193,7 +197,6 @@ protobuf {
plugins {
grpc {
option 'lite'
option '@generated=omit'
}
}
}

View File

@ -80,7 +80,7 @@ class JavaGrpcGenerator : public protobuf::compiler::CodeGenerator {
java_grpc_generator::ProtoFlavor flavor =
java_grpc_generator::ProtoFlavor::NORMAL;
java_grpc_generator::GeneratedAnnotation generated_annotation =
java_grpc_generator::GeneratedAnnotation::JAVAX;
java_grpc_generator::GeneratedAnnotation::OMIT;
bool disable_version = false;
for (size_t i = 0; i < options.size(); i++) {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/lb/v1/load_balancer.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class LoadBalancerGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to obtain stats for verifying LB behavior.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class LoadBalancerStatsServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/metrics.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class MetricsServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service used to control reconnect server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ReconnectServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* performance with various types of payload.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class TestServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* that case.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class UnimplementedServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to dynamically update the configuration of an xDS test client.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateClientConfigureServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A service to remotely control health status of an xDS test server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/testing/test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class XdsUpdateHealthServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: test/echo/proto/echo.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class EchoTestServiceGrpc {

View File

@ -45,7 +45,6 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
"io.perfmark:perfmark-api:0.27.0",
"junit:junit:4.13.2",
"org.apache.tomcat:annotations-api:6.0.53",
"org.checkerframework:checker-qual:3.12.0",
"org.codehaus.mojo:animal-sniffer-annotations:1.24",
]

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/lookup/v1/rls.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class RouteLookupServiceGrpc {

View File

@ -8,9 +8,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* information.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/channelz/v1/channelz.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ChannelzGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/health/v1/health.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class HealthGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/reflection/v1/reflection.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ServerReflectionGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/reflection/v1alpha/reflection.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ServerReflectionGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* AnotherDynamicService
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class AnotherDynamicServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/reflection_test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class AnotherReflectableServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A DynamicService
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class DynamicServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/reflection_test.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ReflectableServiceGrpc {

View File

@ -15,12 +15,3 @@ java_library(
artifact("org.codehaus.mojo:animal-sniffer-annotations"),
],
)
# javax.annotation.Generated is not included in the default root modules in 9,
# see: http://openjdk.java.net/jeps/320.
java_library(
name = "javax_annotation",
neverlink = 1, # @Generated is source-retention
visibility = ["//visibility:public"],
exports = [artifact("org.apache.tomcat:annotations-api")],
)

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* A simple service for test.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/protobuf/simpleservice.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class SimpleServiceGrpc {

View File

@ -14,9 +14,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* a new call to change backend reporting frequency.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: xds/service/orca/v3/orca.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class OpenRcaServiceGrpc {

View File

@ -12,9 +12,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* the multiplexed singleton APIs at the Envoy instance and management server.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: envoy/service/discovery/v3/ads.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class AggregatedDiscoveryServiceGrpc {

View File

@ -4,9 +4,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: envoy/service/load_stats/v3/lrs.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class LoadReportingServiceGrpc {

View File

@ -7,9 +7,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* Defines the Rate Limit Quota Service (RLQS).
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: envoy/service/rate_limit_quota/v3/rlqs.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class RateLimitQuotaServiceGrpc {

View File

@ -9,9 +9,6 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
* also be used to get the current xDS states directly from the client.
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: envoy/service/status/v3/csds.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ClientStatusDiscoveryServiceGrpc {