I know the question is a bit old but I started using this which I think would be cleaner if you do not care about what libraries being injected into your module.
root build.gradle
ext {
commonDependencies = [
// Layout Libraries
constraintLayoutApi : "androidx.constraintlayout:constraintlayout:$constraintlayout_version",
materialApi : "com.google.android.material:material:$material_version",
flexboxApi : "com.google.android:flexbox:$flexbox_version",
// Image library (Picasso is alternative)
glideImpl : "com.github.bumptech.glide:glide:$glide_version",
glideCompilerAnno : "com.github.bumptech.glide:compiler:$glide_version",
// Network library (Volley is alternative)
retrofitImpl : "com.squareup.retrofit2:retrofit:$retrofit_version",
retrofitJacksonImpl : "com.squareup.retrofit2:converter-jackson:$retrofit_version",
retrofitScalarsImpl : "com.squareup.retrofit2:converter-scalars:$retrofit_version",
retrofitJava8Impl : "com.squareup.retrofit2:converter-java8:$retrofit_version",
// Dependency Injection
daggerImpl : "com.google.dagger:dagger:$dagger_version",
daggerCompilerAnno : "com.google.dagger:dagger-compiler:$dagger_version",
// we add this so we can use the android support libraries
daggerAndroidSupportImpl: "com.google.dagger:dagger-android-support:$dagger_version",
daggerProcessorAnno : "com.google.dagger:dagger-android-processor:$dagger_version"
]
}
and in app build.gradle:
dependencies {
api "androidx.appcompat:appcompat:$app_compact_version"
api "com.google.android.gms:play-services-auth:$play_service_version"
commonDependencies.each { key, value ->
if (key.endsWith('Anno')) {
annotationProcessor value
} else if (key.endsWith('Impl')) {
implementation value
} else if (key.endsWith('Api')) {
api value
}
}
}
As you can see I am checking for API, Implementation, and Annotation by the suffix of the key in the root gradle file.