Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find symbol class "Generated" for Dagger 2

I just started doing dependency injection using Dagger 2. When I spun up my modules, components and tried to build my application, gradle threw the error

Error:(4, 24) error: cannot find symbol class Generated

I dug into it and found that the error is in one of the classes Dagger generates to do DI. The particular class that's missing was javax.annotation.Generated and the line throwing the error is the line that anntotates a Dagger generated class as @Generated("dagger.internal.codegen.ComponentProcessor")

This question helped in finding the solution which is to add the javax package as a dependency by adding the line compile 'org.glassfish:javax.annotation:10.0-b28' to my gradle build file. This led to a successful build.

My question is, why is that not added as a transitive dependency for Dagger or why hasn't anyone else faced this particular issue (I assume so, since I couldn't find any question here regarding this?

like image 394
x-treme Avatar asked Apr 22 '15 00:04

x-treme


2 Answers

TL;DR use Dagger >= 2.1

Alex is right, but it's better to add JSR250 dependency instead of GlassFish

provided 'javax.annotation:jsr250-api:1.0' 

or for the latest gradle plugin:

compileOnly 'javax.annotation:jsr250-api:1.0' 
like image 198
tomrozb Avatar answered Sep 21 '22 02:09

tomrozb


Read this for more info: https://github.com/google/dagger/issues/95

Basically, the solution is to do what you've already done which is include the glassfish javax annotation library.

like image 28
Alex Fu Avatar answered Sep 23 '22 02:09

Alex Fu