I know this question is a bit outdated, but I started using it, which I think will be cleaner if you don't care which libraries are introduced 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 the build.gradle application:
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 the API, implementation, and annotation by key suffix in the Gradle root file.
source share