![](/img/trans.png)
[英]Java/IntelliJ not recognising the “Dagger” keyword for Dagger2 Components
[英]Dagger2 do not generate Component class in regular Java project (IDEA IntelliJ)
這是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'
}
這是使匕首運行所需的全部條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.