さて、私は自分の Android プロジェクトをクリーン アーキテクチャを使用するように移行しています。
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' で 'provided' を変更しようとしました。まだ機能していません。
奇妙なのは、compileTestJava が失敗した後、生成された DaggerTestComponent.java がdomain/build/classes/testにあることです。では、それが生成されている場合、なぜこのコンパイル エラーが発生するのでしょうか?
この問題はテスト ソースでのみ発生することに注意してください。メイン ソースで使用されている Dagger 2 のソースを生成しました。
アップデート:
DaggerTestComponent を使用しようとしていたすべての場所にコメントし、再度ビルドを試みました。domain/build/classes/testで、DaggerTestComponent.java だけでなく、コンパイルの結果の .class も見つけることができます。つまり、ソースファイルを生成してコンパイルしています。それを使用したファイルのコンパイルが機能しないのはなぜですか? 生成されたソースは、他のソースのコンパイル時にまだ準備ができていないなど、順序の問題のようです。