googleapis / googleapis/google-cloud-java

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

Đang mở
#12,531 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
priority: p3 semver: major type: feature request
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.