grpc-kotlin icon indicating copy to clipboard operation
grpc-kotlin copied to clipboard

Annotations conflict when used with Dagger Hilt

Open kureuil opened this issue 5 years ago • 0 comments
trafficstars

I'm using gRPC Kotlin in an Android application and I wanted to try the new Dagger Hilt integration.

When compiling an android project with dependency on gRPC Kotlin v0.1.5 and Dagger 2.28.3, the build errors during the :app:checkDebugDuplicateClasses step with the following errors (see this minimal working example):

> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class javax.annotation.Generated found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.PostConstruct found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.PreDestroy found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.Resource found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.Resource$AuthenticationType found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.Resources found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.security.DeclareRoles found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.security.DenyAll found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.security.PermitAll found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.security.RolesAllowed found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)
  Duplicate class javax.annotation.security.RunAs found in modules jetified-javax.annotation-api-1.2.jar (javax.annotation:javax.annotation-api:1.2) and jetified-jsr250-api-1.0.jar (javax.annotation:jsr250-api:1.0)

I'm not very familiar with the Java annotations ecosystem but it would seem that these packages provide the same annotation classes so I'm not sure if this problem is really worth an issue here but maybe there could be a note in the docs that this dependency can cause some issues.

For now I've excluded the javax.annotation-api from gRPC Kotlin dependencies and everything seems to work correctly but I'd like to know if there is any better solution to this problem:

api("io.grpc:grpc-kotlin-stub:0.1.5") {
    exclude group: "javax.annotation", module: "javax.annotation-api"
}

kureuil avatar Sep 02 '20 13:09 kureuil