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

前端 未结 8 966
抹茶落季
抹茶落季 2020-12-14 16:21

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 o

8条回答
  •  难免孤独
    2020-12-14 16:34

    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:

提交回复
热议问题