【问题标题】:Dagger2 do not generate Component class in regular Java project (IDEA IntelliJ)Dagger2 在常规 Java 项目(IDEA IntelliJ)中不生成组件类
【发布时间】:2017-06-28 09:55:22
【问题描述】:

这是 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* 类。

【问题讨论】:

标签: java intellij-idea gradle dagger


【解决方案1】:

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

这是我的 .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'

}

这就是让匕首运行所必需的一切。

【讨论】:

    猜你喜欢
    • 2021-03-20
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 2021-03-24
    相关资源
    最近更新 更多