I downloaded the Coffee sample application and bring it into my IDE. After I run mvn clean
, my IDE reports compilation error as:
And it won't get fixed until I run mvn compile
. Obviously the sample code refers to some class that is generated by the tool.
I am quite surprised by this design as before you get the project compiled, you won't have a project that is ready to compile (looks like), kind of like you have to eat your own egg to get born.
Question: is this the normal usage scenario of dagger2? Or did I miss something?
Yes. Dagger makes use of the Java Annotation Processing Tool , which hooks into the compilation process. During the annotation processing, the DaggerCoffeeApp_Coffee
class is generated, after which the original and generated source code is compiled as a whole.
Needless to say, before compilation this class does not exist yet. That is why your IDE cannot find it, and marks it as an error. After running mvn compile
, it can find the class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.