googleapis / googleapis/google-cloud-java

[sdk-platform-java] Compiling generated libraries with Java 9+ fails due to javax.annotation.Generated

未关闭
#12,531 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
priority: p3 semver: major type: feature request
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
157

描述

For example, compiling a "self-service" generated library with `./gradlew check` fails:
```
> Task :proto-google-cloud-retail-v2alpha-java:compileJava
/tmp/google-cloud-retail-v2alpha-java/proto-google-cloud-retail-v2alpha-java/src/main/java/com/google/cloud/retail/v2alpha/LocationName.java:27: error: cannot find symbol
import javax.annotation.Generated;
```

The `javax.annotation` package space is really a mess from the perspective of Java 9+ JPMS, and it has caused a lot of trouble to many people with Java 9+.

The right solution for Java 9+ is to drop `javax.annotation.Generated` and migrate to `javax.annotation.processing.Generated`. However, doing so will cause Java 8 to fail with the same "cannot find symbol" error. An option would be to completely drop using the annotation. However, the gRPC proto compiler generated files with the annotation, so they are out of our control:
```
@javax.annotation.processing.Generated(
value = "by gRPC proto compiler",
comments = "Source: google/cloud/retail/v2alpha/product_service.proto")
```

A workaround for the users hitting this issue is to declare the following dependency, but this isn't really the right solution.
```gradle
implementation 'javax.annotation:javax.annotation-api:1.3.2'
```

Refs:
https://github.com/google/dagger/issues/880
https://github.com/grpc/grpc-java/issues/3633
https://github.com/vavr-io/vavr/issues/2154

贡献指南

打开贡献指南

调研方向

首先,在 proto-google-cloud-retail-v2alpha-java 之类的生成库中使用 ./gradlew check 重现失败,然后检查生成的 LocationName.java 的 import 和 gRPC proto 编译器配置。比较 issue 中描述的 Java 8 和 Java 9+ 注解约束。完成的标准是:生成库在受支持的 Java 版本中编译时不需要 javax.annotation-api workaround。

由索引模型根据 Issue 内容生成。

评估

技术栈
grpc, java
领域
build-system
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。