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

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


Finally I made it!

I had to add the apt and the idea plugin so right now my build.gradle file look like this:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.4"
    }
}

apply plugin: "net.ltgt.apt"
apply plugin: 'java'
apply plugin: 'idea'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile 'com.google.dagger:dagger:2.0.1'
    apt 'com.google.dagger:dagger-compiler:2.0.1'
}

you must manually enable the annotation processing in IntelliJ.

From: Settings --> Build, Execution, Deployment --> Compiler --> Annotation Processors --> Enable annotation processing and Obtain processors from project classpath

then rebuild the project and you will find the generated classes in the project.

Please note that I have used this solution in a (java) android project.