Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java/IntelliJ not recognising the "Dagger" keyword for Dagger2 Components

I'm probably missing something very basic here, so hopefully it's not a hard question.

My equivalent of

CoffeeShop coffeeShop = DaggerCoffeeShop.create();

is not being recognised by the IDE (IntelliJ). This is a native Java project. The "DaggerCoffeShop" part is all red.

The component is using this syntax:

@Component(modules = <ModuleClassName>.class)
public interface CoffeeShop {
    // some methods.
    // does it matter what goes in here for it to recognise the component?
}

The "ModuleClassName" is the name of a module annotated with @Module and includes @Provides methods.

To get the libs I'm using this in Gradle:

compile 'com.google.dagger:dagger:2.4'
compile 'com.google.dagger:dagger-compiler:2.4'

Is that all I need? I don't get any errors for any of the annotations, it's just this Dagger keyword it can't recognise. What am I missing?

Any help or direction appreciated. I'm not finding the documentation to be that great for beginners like me.

like image 490
Michael Vescovo Avatar asked May 07 '16 05:05

Michael Vescovo


1 Answers

Your annotation processing is probably not enabled.

In Settings - > Compiler -> Annotation Processor -> Enable annotation processing

Afterwards, Rebuild Project

If it still thinks the files don't exist (despite the app running properly), you'll have to add the generated source folder as a source folder: File -> Project Structure -> Modules -> select your project -> Sources -> right click on the generated folder with the Dagger stuff in it -> Sources


And compile 'com.google.dagger:dagger-compiler:2.4' should be either apt scoped or annotationProcessor scoped. If you use Kotlin, then kapt scoped

like image 80
EpicPandaForce Avatar answered Oct 22 '22 03:10

EpicPandaForce