上下文
我已经用 Gradle
作为构建系统在 java 中启动了一个个人项目,我想使用 Dagger 2 作为 DI。这样做的主要原因是习惯该库并能够在更大的项目中轻松使用它。
我尝试了什么
我已经成功制作了 Google sample在 IntelliJ IDEA 上运行
问题
IntelliJ IDEA 一直告诉我它无法解析生成的类(在本例中为 DaggerCoffeeApp_Coffee
)。不知道写的代码是否正确有点烦人(尤其是在学习使用 Dagger 2 时)。
所有java类都与Google sample相同.这是我的 build.gradle
文件:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.dagger:dagger:2.0.1'
compile 'com.google.dagger:dagger-compiler:2.0.1'
}
问题
有什么方法可以让 IntelliJ IDEA 将 DaggerCoffeeApp_Coffee
识别为生成的类(因此可以通过 `ctrl + 左键单击来实现它)?
最佳答案
我发现的最简单的方法:
添加
idea
插件并添加 Dagger2 依赖,如下所示:plugins { id "net.ltgt.apt" version "0.10" } apply plugin: 'java' apply plugin: 'idea' 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' }
为 IntelliJ 打开
Annotation Processing
:转到Settings
并搜索Annotation Processors
,勾选 Enable annotation processing,如下图所示:
关于java - 有什么方法可以让 IntelliJ IDEA 在 Java 项目中识别 Dagger 2 生成的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444356/