java - Dagger2在常规Java项目(IDEA IntelliJ)中不会生成Component类

标签 java intellij-idea gradle dagger

这是Gradle:

plugins {
    id "net.ltgt.apt" version "0.10"
}

group 'hello'
version '1.0-SNAPSHOT'

apply plugin: 'java'

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'
}

这是类:

零件 :
import dagger.Component;
/**
 * Created by bart on 27/06/2017.
 */

@Component(modules = {MainModule.class})
public interface MainComponent {
    Service myService();

    void inject(Manager aManager);
}

当我在控制台中启动./gradlew构建时,一切都编译正确。
我不明白为什么我无法访问Manager类中的DaggerMainComponent类或任何Dagger *类。

最佳答案

确保您的注释处理器已打开。
文件->设置->构建,执行,部署->编译器->注释处理器
单击“启用注释处理器,然后选择从项目类路径中获取处理器

这是我的.gradle文件的样子

plugins {
    id 'java'
    id 'net.ltgt.apt-idea' version "0.15"
}

group 'DaggerExample'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'com.google.dagger:dagger:2.23.2'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.23.2'

}

这是使 Dagger 运行所需的全部条件。

关于java - Dagger2在常规Java项目(IDEA IntelliJ)中不会生成Component类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44799248/

相关文章:

java - 我如何使用不同版本的java

java - 搜索jar文件中的文件(包括要查找的jar文件中的Jython类文件)

gradle - 如何在gradle 2.2+中的根项目中指定checkstyle config的相对路径

gradle - 如何在使用 Gradle 构建 fat jar 时编译不同的口味

gradle - GWT、Gradle、多个 SLF4J 绑定(bind)错误

java - jetty 9 : Setting up handlers and connectors

java - 在 SharedPreference 中保存通用类型的列表

java - org.json.JSONException : End of input at character 0

java - 如何在 IntelliJ IDEA 中以相同的顺序运行多个类?

maven - IntelliJ 使用 Maven 而不是 JUnit 运行单元测试