[英]The generated class for Component of Dagger 2 is not found in compileTestJava of Gradle's Java Plugin
好吧,我正在遷移我的Android項目以使用Clean Architecure:
https://github.com/android10/Android-CleanArchitecture
這意味着我的部分代碼在域模塊中(純Java,不依賴於Android)。 對於這個項目,我使用的是Dagger 2,它使用注釋處理器生成源代碼(在編譯期間)。
我的項目有以下Gradle配置:
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
dependencies {
def domainDependencies = rootProject.ext.domainDependencies
def domainTestDependencies = rootProject.ext.domainTestDependencies
provided domainDependencies.daggerCompiler
provided domainDependencies.javaxAnnotation
compile domainDependencies.dagger
compile domainDependencies.rxJava
compile domainDependencies.joda
testCompile domainTestDependencies.junit
testCompile domainTestDependencies.assertJ
testCompile domainTestDependencies.mockito
testCompile domainTestDependencies.jMockLegacy
testCompile domainTestDependencies.commonsCsv
}
在我的測試源中,我創建了接口TestComponent,並且Dagger用於生成DaggerTestComponent。 當我嘗試通過命令行或Android Studio構建我的項目時,我收到無法找到符號的編譯錯誤,然后: 任務':domain:compileTestJava'的執行失敗 。
我試圖用'compile'和'testCompile'來改變'提供'。 它仍然無法正常工作。
奇怪的是,在compileTestJava失敗后,我可以在domain / build / classes / test中找到生成的DaggerTestComponent.java。 那么,如果它正在生成,為什么我收到這個編譯錯誤?
重要的是要注意,此問題僅發生在測試源中。 我已經生成了主要來源中使用的Dagger 2的來源。
更新:
我評論了每個嘗試使用DaggerTestComponent並試圖再次構建的地方。 在domain / build / classes / test中 ,現在我不僅可以找到DaggerTestComponent.java,還可以找到編譯產生的.class。 因此,它生成源文件並進行編譯。 為什么使用它的文件編譯不起作用? 這似乎是一些訂單問題,比如在編譯其他源時生成的源還沒有准備好。
感謝@EpicPandaForce,如果有一個純Java的APT插件,我就開始破舊了。 搜索后,我找到了這個:
https://github.com/tbroyer/gradle-apt-plugin
我剛剛應用了該插件並使用apt和testApt更改了我的依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.