androidgradleauto-value

Android Gradle annotationProcessor not available in parent module


I'm having the following setup:

ProjectA build.gralde:

dependencies {
    compile (project(':ProjectB'))
}

ProjectB build.gradle:

dependencies {
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
    compile "com.google.auto.value:auto-value:1.3"
    annotationProcessor "com.google.auto.value:auto-value:1.3"
}

And SomeClass in ProjectA that is implementing Parcelable

@AutoValue
public abstract class SomeClass implements Parcelable {
...
}

AutoValue won't generate any Parcelable related methods in AutoValue_SomeClass.

However, if I include auto-value-parcel annotationProcessor directly to ProjectA, the problem is resolved.

ProjectA build.gralde:

dependencies {
    compile (project(':projectB'))
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
}

Can anyone explain how auto-value-parcel annotationProcessor is being excluded from ProjectA?


Solution

  • annotationProcessor dependencies are not exported to other projects. Also these are not exported with libraries.

    AutoValue itself works, because you defined it with a compile dependency. This is something you should not do either. So an better dependency setup would look like...

    ProjectB

    dependencies {
        provided "com.jakewharton.auto.value:auto-value-annotations:$autoValueVersion"
        annotationProcessor "com.google.auto.value:auto-value:$autoValueVersion"
        annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$autoValueParcelVersion"
    }
    

    ProjectA

    dependencies {
        compile project(':ProjectB')
        provided "com.jakewharton.auto.value:auto-value-annotations:$autoValueVersion"
        annotationProcessor "com.google.auto.value:auto-value:$autoValueVersion"
        annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$autoValueParcelVersion"
    }
    

    But not having annotationProcessor run on all projects would be even better.