Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way of making IntelliJ IDEA recognizing Dagger 2 generated classes in a Java project?

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)?

like image 512
Alberto S. Avatar asked Oct 30 '15 20:10

Alberto S.


1 Answers

Simplest way I found:

  1. 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' } 
  2. Turn on Annotation Processing for IntelliJ: Go to Settings and search for Annotation Processors, check Enable annotation processing like below image:

enter image description here

like image 164
Hani Avatar answered Sep 20 '22 03:09

Hani