4

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?

dkarmazi
  • 3,199
  • 1
  • 13
  • 25
  • What if you put both `annotationProcessor auto-value...` _before_ `annotationProcessor auto-value-parcel`, both in module B? – wasyl May 05 '17 at 21:38
  • no luck, tried pretty much all combinations of ordering these 3 items – dkarmazi May 05 '17 at 21:59

1 Answers1

9

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.

tynn
  • 38,113
  • 8
  • 108
  • 143
  • Thanks for clear explanation! I've been coming to the same conclusion that annotationProcessor is effective within the scope of it's module only. I tried searching for any documentation on annotationProcessor, but couldn't find anything. Would you mind sharing any resources/docs on annotationProcessor? – dkarmazi May 11 '17 at 17:43