[英]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.