The generated class for Component of Dagger 2 is not found in compileTestJava of Gradle's Java Plugin

3.5k views Asked by At

Well, I'm migrating my Android project to use the Clean Architecure:

https://github.com/android10/Android-CleanArchitecture

This means that part of my code is within the domain module (pure Java, no dependency with Android). For this project, I'm using Dagger 2, that generates source using the annotation processor (during compile time).

I have the following Gradle's configuration for my project:

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
}

In my test source, I created the interface TestComponent and the Dagger is suposed to generate the DaggerTestComponent. When I try to build my project either through command line or Android Studio, I receive compilation errors of cannot find symbol and then: Execution failed for task ':domain:compileTestJava'.

I tried to change the 'provided' with 'compile' and 'testCompile'. It's still not working.

What is strange is that, after the failure of the compileTestJava, I can find the generated DaggerTestComponent.java in domain/build/classes/test. So, if it's being generated, why am I receiving this compile error?

It's important to note that this problem only happens in the test source. I have generated source of Dagger 2 being used in the main source.

UPDATE:

I commented every place that was trying to use the DaggerTestComponent and tried to build again. In the domain/build/classes/test, now I can find not only the DaggerTestComponent.java but also the .class resulted of the compilation. So, it's generating the source file and compiling it. Why is the compilation of files using it not working? It seems like some order problem, like the generated source isn't ready yet at the time of the compile of the other sources.

1

There are 1 answers

1
Fernando Camargo On BEST ANSWER

Thanks to @EpicPandaForce, I started worndering if there was a APT plugin for pure Java too. After searching, I found this one:

https://github.com/tbroyer/gradle-apt-plugin

I just applied that plugin and changed my dependencies with apt and testApt.