【发布时间】:2017-01-25 03:43:20
【问题描述】:
非 Android 应用(IDE 是 IntelliJ IDEA)中的 Dagger 2 让我筋疲力尽。
build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
}
}
apply plugin: 'java'
apply plugin: 'net.ltgt.apt'
dependencies {
compile 'com.google.dagger:dagger:2.8'
apt 'com.google.dagger:dagger-compiler:2.8'
compileOnly 'javax.annotation:jsr250-api:1.0'
}
组件
@Component(modules = {MyModule.class}) public interface MyComponent {}
模块
@Module class MyModule {}
主要
DaggerMyComponent component = DaggerMyComponent.builder().build();
编译器说
找不到符号 DaggerMyComponent
绝对没有更多的想法可能是错误的:(
顺便说一句,如果我运行gradlew clean build --refresh-dependencies,没有错误,一切正常!
但因为只有我在 IDE 中使用“重建项目” - 再次出错。可能是 IDEA 错误(是时候回到 Eclipse)?
是的,我添加了包含生成类的目录作为内容根目录,因此 IDE 可以看到 DaggerMyComponent。
【问题讨论】:
标签: java intellij-idea dagger-2