I have an Android application module (A) and an Android library module (B). Both (A) and (B) contain these same dependencies:
dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
However in my project the module (A) is depending on module (B)
so I did search on the stack overflow about how could I implement Don't Repeat Yourself
design pattern so that I will include those dependencies only in the module (B) and I found this useful but I didn't find how could I make this dependency
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1
shared between those two modules so how could I do that?
Annotation processors are build-time dependencies, but not runtime-dependencies. You should not force all users of your library (and the users of their libraries) to use a specific annotatuon processor. In contrast to libraries, just because you are using it, it doesn't mean the users of your library have to use it as well.
In some rare cases, it might be sensible to create a Gradle plugin to simplify the build configuration for the users. Such plugin could automatically add both, the annotation processor and the library, to the project. Anyway, having to declare two dependencies – even if there are effectivly only used together – does probably not justify the creation of such plugin.
You might decide to use a specific annotation processor for the whole repostory. In this case, you might enable the annotation processor for all Gradle projects in that repostory from the build.gradle
in the root directory.
allprojects {
pluginManager.withPlugin('java') {
dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
}
}