In Maven there is a very useful feature when you can define a dependency in the
section of the parent POM, and reference that depen
To keep you gradle file clean, we can group dependency in an array and implement them later.
// declare versions of library
final RetrofitVersion = '2.3.0' final OkHttpVersion = '3.9.1'
// Using version in library and add dependency along with access name(like retrofit(first one))
final networkDependencies = [ retrofit : "com.squareup.retrofit2:retrofit:${RetrofitVersion}", retrofitGsonConverter: "com.squareup.retrofit2:converter-gson:${RetrofitVersion}", retrofitRxJavaAdapter: "com.squareup.retrofit2:adapter-rxjava2:${RetrofitVersion}", okHttp3 : "com.squareup.okhttp3:okhttp:${OkHttpVersion}", okHttp3Logging : "com.squareup.okhttp3:logging-interceptor:${OkHttpVersion}" ]
// Implement all the dependency from array
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation networkDependencies.values() }
So the final code will look like this:
final RetrofitVersion = '2.3.0'
final OkHttpVersion = '3.9.1'
final networkDependencies = [
retrofit : "com.squareup.retrofit2:retrofit:${RetrofitVersion}",
retrofitGsonConverter: "com.squareup.retrofit2:converter-gson:${RetrofitVersion}",
retrofitRxJavaAdapter: "com.squareup.retrofit2:adapter-rxjava2:${RetrofitVersion}",
okHttp3 : "com.squareup.okhttp3:okhttp:${OkHttpVersion}",
okHttp3Logging : "com.squareup.okhttp3:logging-interceptor:${OkHttpVersion}"
]
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation networkDependencies.values()
}