Closed
Closed
Copy link
Milestone
Description
What version of gRPC-Java are you using?
1.71.0
What is your environment?
Microsoft Windows [Version 10.0.26100.3775]
openjdk version "23.0.2" 2025-01-21
OpenJDK Runtime Environment (build 23.0.2+7-58)
OpenJDK 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)
What did you expect to see?
No error
What did you see instead?
Compiler error when I add a dependency on gRPC-Java:
[ERROR] module com.google.protobuf reads package javax.annotation from both annotations.api and jsr305
(com.google.protobuf is not relevant, I get the same error from all modules in my project)
Steps to reproduce the bug
io.grpc:grpc-api:jar:1.71.0:compile depends on com.google.code.findbugs:jsr305:jar:3.0.2:compile but the README.md instructs Java9 users to also add a dependency on:
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
Both these packages contain a javax.annotation package which means that the package is split across multiple Java Modules which is illegal in Java 9+
Consider dropping the dependency on JSR 305 as it's basically a dead project anyway.
Metadata
Metadata
Assignees
Labels
No labels
Activity
cowwoc commentedon Apr 9, 2025
This workaround worked for me:
Additionally, please replace:
with:
You'll have to update the package name of the imported annotations but this artifact is much better than Tomcat's. It is the official replacement for javax.annotations and it includes
module-info.javafor Java9+ users.[-]Cannot use library from Java 9+ due to split package (JSR 305 vs org.apache.tomcat:annotations-api)[/-][+]Cannot use library from Java 9+ due to split package (JSR 305 vs annotations-api)[/+]kannanjgithub commentedon Apr 15, 2025
The gRPC compiler already has an option of specifying to omit emitting javax annotation for Generated and instead use
io.grpc.stub.annotations.GrpcGenerated. There is plan to make this the default Generated annotation to be emitted by the codegen plugin.Example pom.xml fragment for the codegen plugin:
cowwoc commentedon Apr 24, 2025
You're right. This works.
Are there any plans to remove the dependency on JSR 305?
kannanjgithub commentedon May 13, 2025
Yes we will make the
@generated=omitbehavior the default.kannanjgithub commentedon Jun 3, 2025
@generated=omit is now the default, fixed in PR #12080.