简体   繁体   English

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

[英]Dagger2 do not generate Component class in regular Java project (IDEA IntelliJ)

Here is the Gradle : 这是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'
}

And here are the classes : 这是类:

Component : 零件 :

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

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

    void inject(Manager aManager);
}

When I launch the ./gradlew build in the console, all is compiled OK. 当我在控制台中启动./gradlew构建时,一切都已编译好。 I don't get why I do not have access to DaggerMainComponent class or any Dagger* class in my Manager class. 我不明白为什么我无法访问Manager类中的DaggerMainComponent类或任何Dagger *类。

Make sure your Annotation Processor is turned on. 确保您的注释处理器已打开。 File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processor Click on " Enable annotation processor and choose obtain processors from project classpath 文件->设置->构建,执行,部署->编译器->注释处理器单击“ 启用注释处理器并选择从项目类路径获取处理器

and here is what my .gradle file looks like 这是我的.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'

}

This is all what necessary to make dagger run. 这是使匕首运行所需的全部条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM