Context
I have started a personal project in java with Gradle
as the build system and I want to use Dagger 2 as a DI. The main reason of doing that is to get used to that library and be able to use it easily in bigger projects.
What have I tried
I've managed to make the Google sample runs on IntelliJ IDEA
Problem
IntelliJ IDEA keeps telling me that it cannot resolve the generated class (in this case DaggerCoffeeApp_Coffee
). It's a bit annoying not to know if the written code is correct (specially when you are learning to use Dagger 2).
All java classes are the same as the Google sample. Here is my build.gradle
file:
apply plugin: 'java' repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compile 'com.google.dagger:dagger:2.0.1' compile 'com.google.dagger:dagger-compiler:2.0.1' }
Question
Is there any way to make IntelliJ IDEA recognize DaggerCoffeeApp_Coffee
as a generated class (and so make it possible to go to its implementation by `ctrl + left click)?
Simplest way I found:
Add idea
plugin and add Dagger2 dependency like below:
plugins { id "net.ltgt.apt" version "0.10" } apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compile 'com.google.dagger:dagger:2.11' apt 'com.google.dagger:dagger-compiler:2.11' }
Turn on Annotation Processing
for IntelliJ: Go to Settings
and search for Annotation Processors
, check Enable annotation processing like below image:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With