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

前端 未结 8 934
抹茶落季
抹茶落季 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:42

    Here's the solution that worked for me:

    File -> Project Structure -> (select your project under list of modules) -> Open 'Dependencies' tab

    Then, click on green '+' sign, select 'JARs or directory' and select 'build/classes/main' folder.

    Another solution would be to link folder with build class files using 'dependencies' block inside build.gradle:

    https://stackoverflow.com/a/22769015/5761849

    0 讨论(0)
  • 2020-12-14 16:50

    Using IntelliJ IDEA 2019.1 and Gradle 5.4.1, this seems to be enough:

    plugins {
        id 'java'
    }
    
    version '1.0-SNAPSHOT'
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        testImplementation group: 'junit', name: 'junit', version: '4.12'
    
        implementation 'com.google.dagger:dagger:2.23.1'
        annotationProcessor 'com.google.dagger:dagger-compiler:2.23.1'
    }
    

    I don't know the minimal versions for which this solution works, though.

    0 讨论(0)
提交回复
热议问题